Javascript 判断浏览器类型

来源:互联网 发布:du(仅限数据连接) 编辑:程序博客网 时间:2024/06/05 14:45
//检测IE内核var browser={versions:function(){var u = navigator.userAgent, app = navigator.appVersion;return {trident: u.indexOf('Trident') > -1, //IE内核presto: u.indexOf('Presto') > -1, //opera内核webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//火狐内核mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器iPhone: u.indexOf('iPhone') > -1 , //是否为iPhone或者QQHD浏览器iPad: u.indexOf('iPad') > -1, //是否iPadwebApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部};}(),language:(navigator.browserLanguage || navigator.language).toLowerCase()}if(browser.versions.trident){console.log("ie");$("#login").css("background","#282828");}else if(browser.versions.mobile){}var isIE=!!window.ActiveXObject; var isIE6=isIE&&!window.XMLHttpRequest; var isIE8=isIE&&!!document.documentMode; var isIE7=isIE&&!isIE6&&!isIE8; if (isIE6 || isIE8|| isIE7){$("#login").css("background","#282828");} if(isIE){console.log("ie");}

0 0