现在的位置: 首页 > 综合 > 正文

Javascript 判断浏览器

2014年01月02日 ⁄ 综合 ⁄ 共 954字 ⁄ 字号 评论关闭
                var Sys = {};
                var ua = navigator.userAgent.toLowerCase();
                if (window.ActiveXObject)//IE
                    Sys.ie = ua.match(/msie ([/d.]+)/)[1]
                else if (document.getBoxObjectFor)//Firefox
                    Sys.firefox = ua.match(/firefox//([/d.]+)/)[1]
                else if (window.MessageEvent && !document.getBoxObjectFor)//Chrome
                    Sys.chrome = ua.match(/chrome//([/d.]+)/)[1]
                else if (window.opera)//Opera
                    Sys.opera = ua.match(/opera.([/d.]+)/)[1]
                else if (window.openDatabase)//Safari
                    Sys.safari = ua.match(/version//([/d.]+)/)[1];
                //以下进行测试
                if (Sys.ie) alert('IE: ' + Sys.ie);//Sys.ie是版本号
                if (Sys.firefox) alert('Firefox: ' + Sys.firefox);
                if (Sys.chrome) alert('Chrome: ' + Sys.chrome);
                if (Sys.opera) alert('Opera: ' + Sys.opera);
                if (Sys.safari) alert('Safari: ' + Sys.safari);

抱歉!评论已关闭.