js浏览器判断函数

function userBrowser(){  
    var browserName=navigator.userAgent.toLowerCase();  
    if(/msie/i.test(browserName) && !/opera/.test(browserName)){  
        alert("IE");  
        return ;  
    }else if(/firefox/i.test(browserName)){  
        alert("Firefox");  
        return ;  
    }else if(/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName)){  
        alert("Chrome");  
        return ;  
    }else if(/opera/i.test(browserName)){  
        alert("Opera");  
        return ;  
    }else if(/webkit/i.test(browserName) &&!(/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName))){  
        alert("Safari");  
        return ;  
    }else{  
        alert("unKnow");  
    }  
}  

  

posted @ 2017-10-12 16:44  馳騁衿琾  阅读(127)  评论(0编辑  收藏  举报