paween
ดู Blog ทั้งหมด

Java Script Detect Web Browser

เขียนโดย paween

เพิ่มการตรวจจับ Internet Explorer 11

------------------------------------------------------------------------------------

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("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("Mozilla/") != -1)//Loop for Mozilla Firefox, IE11, IE10-
    {
        if(dataget.indexOf("rv:") != -1){
            
            if(dataget.indexOf("Firefox/") != -1){
                if(dataget.indexOf("Android") != -1){
                    document.write('<p>Firefox for Android</p>');       
                }else if (dataget.indexOf("Firefox/") != -1){
                    arrName = dataget.split("Firefox/");
                    Version = parseFloat(arrName[1]);
                    name = "Firefox";
                    writeDetail(name, Version);
                }
            }else{                        
                arrName = dataget.split("rv:");
                Version = parseFloat(arrName[1]);
                name = "Microsoft Internet Explorer";
                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("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("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>');
}
 

ความคิดเห็น

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