如何判断浏览器 然后针对不同的浏览器加入单独的样式

<script>
    window.onload = function() {
        var isChrome = window.navigator.userAgent.indexOf("Chrome") !== -1 
        //alert(isChrome);
        if(isChrome) $("#fotdiv").removeClass('fotdiv a');
        if(isChrome) $("#fotdiv").addClass('fotdiv2 a');


代码如下:

var isChrome = window.navigator.userAgent.indexOf("Chrome") !== -1 
今天发现chrome还是有一些独一无二的东西,基于它们,我们就可以搞出基于特征的判定了。 

代码如下:

var isChrome = window.google && window.chrome 

这两个东西,前者拥有其本地数据库gears,后者不知什么东东,有两个属性csi与loadTimes。


大概就这样
<script type="text/javascript">
var isIE=navigator.userAgent.toUpperCase().indexOf("MSIE")==-1?false:true;
if(isIE) document.getElementById("abc").style.display="";
</script>

或者在head里面这样写
<script type="text/javascript">
var isIE=navigator.userAgent.toUpperCase().indexOf("MSIE")==-1?false:true;
window.onload=function () {
    if(isIE) document.getElementById("abc").style.display="";
}
</script>


.fotdiv a{text-decoration:none; display:inline-block;padding-left:11px;padding-right:11px;} 
.fotdiv2 a{text-decoration:none; display:inline-block;padding-left:8px;padding-right:8px;}
原文地址:https://www.cnblogs.com/zxyun/p/4517404.html