Home  >  Article  >  Web Front-end  >  How does JS determine whether it is an IE browser (including IE10 and IE11)_javascript skills

How does JS determine whether it is an IE browser (including IE10 and IE11)_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:26:141312browse

When I was writing a code copy function today, I discovered this problem. IE11 does not support document.all. It seems that it will become more and more standard in the future

I encountered a strange problem today. There is a page, and I want to specify it to be opened with IE browser. There is no problem in the VS development environment, but when deployed to the server, even if the page is opened with IE, it still prompts "Only supports IE" , I’m so dizzy! !
Determine whether the IE browser uses window.navigator.userAgent. Track this information and find that in the development environment, it is recognized as IE10, but when accessing the server, it is recognized as IE11, but there is no MSIE mark in the userAgent of IE11. This is the reason.

Just change the method of judging IE browser to the following.

The original function writing method: is no longer supported in the new version of ie11

function isIE(){
if (window.navigator.userAgent.indexOf("MSIE")>=1) 
return true; 
else 
return false; 
}

Ie10 and above do not support IE browser judgment, because IE11 no longer supports document.all, the following is the version that supports IE11, of course IE6-8 is also supported

function isIE() { //ie?
 if (!!window.ActiveXObject || "ActiveXObject" in window)
  return true;
  else
  return false;
 }
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn