paween
ดู Blog ทั้งหมด

Java Script Detect Browser

เขียนโดย paween


____________________________________________________________

ความสามารถเพิ่มเคิม
1. แยก Maxthon Web Browser ออกจาก Microsoft Internet Explorer
2. แยก Render Engin ของ LunaScape ตามนี้
    2.1. MSIE
    2.2. Gecko
    2.3. WebKit

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('<p>Google Chrome for Android</p>');
        }else{
                arrName = dataget.split("Chrome/");
                Version = parseFloat(arrName[1]);
                name = "Chrome";
                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('<p>You access from iPad</p>');
        }
        if(dataget.indexOf("iPod") != -1){
        document.write('<p>You access from iPod</p>');
        }
        else if(dataget.indexOf("iPhone") != -1){
        document.write('<p>You access from iPhone</p>');
        }
        else if(dataget.indexOf("Version/") != -1)
        {
        arrName = dataget.split("Version/");
        Version = parseFloat(arrName[1]);
        name = "Safari";
        writeDetail(name, Version);
        }
                
    }
    else if(dataget.indexOf("NanohaBrowser/") != -1)
    {
        arrName = dataget.split("NanohaBrowser/");
        Version = parseFloat(arrName[1]);
        name = "Nanoha Browser";
        writeDetail(name, Version);
    }
    else if(dataget.indexOf("Firefox/") != -1)
    {
        arrName = dataget.split("Firefox/");
        Version = parseFloat(arrName[1]);
        name = "Firefox";
        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('<p>Now you use <b>' + browsName + '</b> Version <b>' + browsVer +'</b></p>');
}
_____________________________________________________-


สัญญาอนุญาตของครีเอทีฟคอมมอนส์
ผลงานนี้ ใช้สัญญาอนุญาตของครีเอทีฟคอมมอนส์แบบ แสดงที่มา-ไม่ใช้เพื่อการค้า-ไม่ดัดแปลง 3.0 ต้นฉบับ.

ความคิดเห็น

ยังไม่มีความคิดเห็น