js判断浏览器

来源:互联网 发布:淘宝卖家发货流程图 编辑:程序博客网 时间:2024/04/29 22:51

function getBrowser(){
 //判断浏览器
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    if (window.ActiveXObject){
          Sys.ie = ua.match(/msie ([/d.]+)/)[1]
     }else if (document.getBoxObjectFor){
        Sys.firefox = ua.match(/firefox//([/d.]+)/)[1]
    }else if (window.MessageEvent && !document.getBoxObjectFor){
         Sys.chrome = ua.match(/chrome//([/d.]+)/)[1]
    }else if (window.opera){
         Sys.opera = ua.match(/opera.([/d.]+)/)[1]
    }else if (window.openDatabase){
         Sys.safari = ua.match(/version//([/d.]+)/)[1];
    }
}