判断ie浏览器(含11),火狐,谷歌浏览器

最近遇到一个问题,需要在不同的浏览器上设置不同的背景颜色.

本来打算用css 

    @-moz-document url-prefix(){.aa{background:pink}};

  @media screen and (-webkit-min-device-pixel-ratio:0) { .aa{background:yellow;}};

来进行判断,但是同时使用着两种,不能生效,就需要用js来进行判断,

$(function(){
if(isFirefox=navigator.userAgent.toUpperCase().indexOf("FIREFOX")>0){

$(".aa").css("background","pink");
}
if(isMozilla=navigator.userAgent.toUpperCase().indexOf("CHROME")>0){
$(".aa").css("background","blue");
}
// if(navigator.userAgent.indexOf("MSIE 9.0")>0)
// {
// alert("ie9");
// }
if (window.ActiveXObject || "ActiveXObject" in window){
$(".aa").css("background","orange");
}
// else{
// alert('我不是IE');
// }
});
这样就能判断不同的浏览器了,但是360浏览器,这个分为两种情况,就ie模式 和极速(chrome)模式,可以将网页强制按照IE模式打开.
posted @ 2016-09-30 11:56  马小乐  阅读(254)  评论(0编辑  收藏  举报