_________________________________________________________________
แว๊ก ขอแก้ไขโค๊ด อันเก่าบังเอิญอัพโค๊ดลับเฉพาะไปด้วย >.<
-แยกการจับ Google Chrome ระหว่าง Desktop, Android, iPhone
dataget = navigator.userAgent;
getBrowser();
function getBrowser(){
if(dataget.indexOf("Lunascape") != -1){
/*
LunaScape have 3 engin.
1. is MSIE
2. is Gecko
3. Webkit
But "Gecko" and "Webkit" almost the same user agent.
So, that two Engin aloso use the same if() function.
*/
function lunaEngin(){
if(dataget.indexOf("MSIE") != -1){
arrName = dataget.split("Lunascape");
Version_Number = parseFloat(arrName[1]);
}else{
arrName = dataget.split("Lunascape/");
Version_Number = parseFloat(arrName[1]);
}
return Version_Number;
}
name = "Lunascape";
Version = lunaEngin();
writeDetail(name, Version);
}
else if(dataget.indexOf("Maxthon") != -1){
name = "Maxthon";
arrName = dataget.split("Maxthon/");
Version = parseFloat(arrName[1]);
writeDetail(name, Version);
}
else if(dataget.indexOf("MSIE") != -1){
name = "Microsoft Internet Explorer";
arrName = dataget.split("MSIE");
Version = parseFloat(arrName[1]);
if(Version >= 8)
{
writeDetail(name, Version);
}
else
{
document.write('<p><b>You still using old Version of Internet Explorer Please Up Grade now for better performance.</b></br>');
document.write("<a href='http://www.ieaddons.com/en/'>Click Here to Download New Version of Internet Explorer!</a>");
//window.close();
}
}
else if(dataget.indexOf("Opera") != -1)
{
keyword = "Opera Mini/";
if(dataget.indexOf(keyword) != -1)
{
arrName = dataget.split(keyword);
Version = parseFloat(arrName[1]);
name = "Opera Mini";
writeDetail(name, Version);
}else{
keyword = "Version/";
arrName = dataget.split(keyword);
Version = parseFloat(arrName[1]);
name = "Opera";
writeDetail(name, Version);
}
}
else if(dataget.indexOf("RockMelt") != -1)
{
arrName = dataget.split("RockMelt/");
Version = parseFloat(arrName[1]);
name = "RockMelt Social Browser";
writeDetail(name, Version);
}
else if(dataget.indexOf("Chrome/") != -1)
{
if(dataget.indexOf("Android") != -1)
{
document.write('
Google Chrome for Android
');}else{
arrName = dataget.split("Chrome/");
Version = parseFloat(arrName[1]);
name = "Chrome";
writeDetail(name, Version);
}
}
else if(dataget.indexOf("Firefox/") != -1)
{
if(dataget.indexOf("Android") != -1){
document.write('
Firefox for Android
');}else{
arrName = dataget.split("Firefox/");
Version = parseFloat(arrName[1]);
name = "Firefox";
writeDetail(name, Version);
}
}
else if(dataget.indexOf("Android") != -1)
{
arrName = dataget.split("Android");
Version = parseFloat(arrName[1]);
name = "Android";
writeDetail(name, Version);
}
else if(dataget.indexOf("Safari") != -1)
{
if(dataget.indexOf("iPad") != -1){
document.write('
You access from iPad
');}
if(dataget.indexOf("iPod") != -1){
document.write('
You access from iPod
');}
else if(dataget.indexOf("iPhone") != -1){
if(dataget.indexOf("CriOS") != -1){
document.write('
Google Chrome for iPhone
');}else if(dataget.indexOf("iPhone") != -1){
document.write('
You access from iPhone
');}
}
else if(dataget.indexOf("Version/") != -1)
{
arrName = dataget.split("Version/");
Version = parseFloat(arrName[1]);
name = "Safari";
writeDetail(name, Version);
}
}
else if(dataget.indexOf("Bada/") != -1)
{
arrName = dataget.split("Bada/");
Version = parseFloat(arrName[1]);
name = "Bada";
writeDetail(name, Version);
}
}
function writeDetail(browsName, browsVer){
document.write('
Now you use ' + browsName + ' Version ' + browsVer +'
');}
_________________________________________________________________
Detect Browser โดย PAWEEN PEECHAWANICH อนุญาตให้ใช้ได้ตาม สัญญาอนุญาตของครีเอทีฟคอมมอนส์แบบ แสดงที่มา-ไม่ใช้เพื่อการค้า-อนุญาตแบบเดียวกัน 3.0 ต้นฉบับ.
ความคิดเห็น