JS如何判断是否为ie浏览器的方法(包括IE10

JavaScript010

JS如何判断是否为ie浏览器的方法(包括IE10,第1张

判断是否IE浏览器用的是window.navigator.userAgent,跟踪这个信息,发现在开发环境,识别为IE10,但访问服务器则识别为IE11,但IE11的userAgent里是没有MSIE标志的,原因就是这个了。

把判断IE浏览器的方法改成如下就可以了。

原来的函数写法:对于新版的ie11已经不支持了

function isIE(){

if (window.navigator.userAgent.indexOf("MSIE")>=1)

return true

else

return false

}

ie10及以上不支持ie浏览器的判断了,因为ie11已经不支持document.all了,下面是支持ie11的版本的,当然ie6-8也是支持的

function isIE() { //ie?

if (!!window.ActiveXObject || "ActiveXObject" in window)

return true

else

return false

}

if ((navigator.userAgent.indexOf('MSIE') >= 0) &&(navigator.userAgent.indexOf('Opera') <0)){alert('你是使用IE')}else

if (navigator.userAgent.indexOf('Firefox') >= 0){alert('你是使用Firefox')}else

if (navigator.userAgent.indexOf('Opera') >= 0){alert('你是使用Opera')}else

{alert('你是使用其他的浏览器浏览网页!')}