浏览器兼容js

方法一:

<script type="text/javascript">

window.GLOBAL = {  //浏览器版本信息

    BROWSER : (function() {

        var u = window.navigator.userAgent.toLocaleLowerCase(),

        msie = /(msie) ([\d.]+)/,

        chrome = /(chrome)\/([\d.]+)/,

        firefox = /(firefox)\/([\d.]+)/,

        safari = /(safari)\/([\d.]+)/,

        opera = /(opera)\/([\d.]+)/,

        ie11 = /(trident)\/([\d.]+)/,

        b = u.match(msie)||u.match(chrome)||u.match(firefox)||u.match(safari)||u.match(opera)||u.match(ie11);

        alert(b);

        alert(b[1]+"-->"+parseInt(b[2]));

        return {NAME: b[1], VERSION: parseInt(b[2])};

        if(b[1].indexOf("trident")!="-1"){

        alert("ie11浏览器");

        }

        if(b[1].indexOf("msie")!="-1"){

        alert("ie11以下浏览器");

        }

        ....其他浏览器以此类推

    })()

}

</script>

方法二:

<script type="text/javascript">

 

if(navigator.userAgent.indexOf("Opera") != -1) 

{  

$("#headerbak").show();//提示框

//daojishi();

    // document.write('您的浏览器是Opera吧?'); 

}else if(navigator.userAgent.indexOf("MSIE") != -1) 

 {

 if(navigator.userAgent.indexOf("MSIE 8.0") != -1) 

 {

  $("#headerbak").hide();

 } 

  else if(navigator.userAgent.indexOf("MSIE 7.0") != -1) 

 {

  $("#headerbak").show();

//daojishi();

 }else if(navigator.userAgent.indexOf("MSIE 6.0") != -1) 

 {

  $("#headerbak").show();

//daojishi();

 }else{

  $("#headerbak").hide();

 } 

 }else if("ActiveXObject" in window){//MSIE X.X在ie11无效,所以单独判断

  $("#headerbak").hide();

 }   

 

// 包含「Firefox」文字列 

else if(navigator.userAgent.indexOf("Firefox") != -1) 

$("#headerbak").hide();

    //document.write('您的浏览器时Firefox吧?'); 

}

// 包含「Netscape」文字列 

else if(navigator.userAgent.indexOf("Netscape") != -1)

$("#headerbak").hide();

    //document.write('您的浏览器时Netscape吧?'); 

// 包含「Safari」文字列 

else if(navigator.userAgent.indexOf("Safari") != -1) 

$("#headerbak").hide();

     //document.write('您的浏览器时Safari 吧?'); 

else{ 

   //document.write('无法识别的浏览器。'); 

$("#headerbak").show();

//daojishi();

var sec=3;

 

</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值