javascript学习指南|javascript中各种判断浏览器的方法

时间:2017-11-19  来源:浏览器  阅读:

代码一(利用small tricks or hacks来判断浏览器)

 代码如下

var ie = !+"v1",
    ie1 = !!top.execScript,
    ie2 = (function() {
        /*@cc_on
        @if (@_jscript)
            return true;
        @else */
            return false;
        /*
        @end
        @*/
    })(),
    ie3 = !("__proto__" in {}),
    ie4 = (function(IE){
        try{
            IE=this.window=!1;
        }catch(e){
            IE=!0;
        };
        return IE;
    })(),
    ie5 = /*@cc_on!@*/false,
    IEVersion = 0/*@cc_on+ScriptEngineMajorVersion()@*/";
 
alert(IEVersion);

判断是来为IE浏览器

 代码如下

function IsIExplorer()
{
    var UA = navigator.userAgent;
    is360se = UA.toLowerCase().indexOf("360se") > -1 ? true : false;
    issougou = UA.toLowerCase().indexOf("metasr") > -1 ? true : false;
    //alert(UA.toLowerCase());
    if (!window.ActiveXObject || is360se || issougou) {
        alert("请您使用Microsoft Internet Explorer(IE)浏览器登录本系统!");
        window.opener = null;
        window.open(" ", "_self", " ");
        window.close();
    }
}

实例三

 代码如下

JS检查是什么浏览器
<script language="JavaScript" type="text/javascript">
function checkFirefoxOrIE(){
userAgent=window.navigator.userAgent.toLowerCase();
if(userAgent.indexOf("firefox")>=1){
Findex=userAgent.indexOf("firefox/");
versionName=userAgent.substr(Findex+"Firefox/".length,3);
document.write("你用的是火狐浏览器!版本是:Firefox/"+versionName+"
");
}
else {
    var name=navigator.appName;
    if(name=="Microsoft Internet Explorer"){document.write("你用的是IE浏览器!");}
    }
}
</script>


上面的方法都是我们常用的并且能判断现在主流的一些浏览器类型了。

javascript学习指南|javascript中各种判断浏览器的方法

http://m.bbyears.com/bangongshuma/37158.html

推荐访问:
相关阅读 猜你喜欢
本类排行 本类最新