As a front-end developer, I can’t avoid IE’s pitfalls. Other browsers are fine, but IE is broken. There is no support for various things. I’m convinced. Some properties and methods are not supported by all versions of IE, while some are partially supported. In the project, the main dividing line is IE8. I believe that most of the projects currently under maintenance and development support IE8 and above. So this article briefly summarizes how to determine whether the browser is IE and its version is 8.0. First of all, some properties and methods are not supported by all versions of IE, so you only need to determine whether it is IEThe following three are the methods I used in my project. If there are new methods, they will be updated. If you have other better methods, please feel free to share them~~
//Choose one function isIE(){ // It is said that Firefox will add the document.all method in the future, so it is recommended to use the other two methods if (document.all) return true; if (!!window.ActiveXObject || "ActiveXObject" in window) return true; if (window.navigator && window.navigator.msSaveOrOpenBlob) return true; } Determine if the browser is IE8 or belowAs I mentioned above, most of the projects under maintenance and development only support IE8 and above. navigator.userAgent function isIE8(){ var DEFAULT_VERSION = 8.0; var ua = navigator.userAgent.toLowerCase(); var isIE = ua.indexOf("msie")>-1; var safariVersion; if(isIE){ safariVersion = ua.match(/msie ([\d.]+)/)[1]; } if (safariVersion <= DEFAULT_VERSION ) { return true }; } If you have special requirements and need to be compatible with lower versions, then: var isIE = !!window.ActiveXObject; var isIE6 = isIE && !window.XMLHttpRequest; var isIE8 = isIE && !!document.documentMode; var isIE7 = isIE && !isIE6 && !isIE8; CSS properties not supported by IE8 and below
Methods not supported by IEBrowse PDF files online. Since IE does not have a built-in PDF reader, you can only download and view them.
The download attribute of the <a> tag is not supported, so you can create a new iframe and set its src attribute if (isIE()){ $("a").bind('click',function(){ var elemIF = document.createElement("iframe"); elemIF.src = FilePath; elemIF.style.display = "none"; document.body.appendChild(elemIF); }); } else { $("a").attr("href",FilePath).attr("download",FileName); } The above is the details of JavaScript judging whether the browser is IE. For more information about JavaScript judging browser, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: How to use Docker container to access host network
>>: Summary of Mysql slow query operations
This article uses examples to illustrate the prin...
Table of contents Method 1: Call the function dir...
1. How to monitor MySQL deadlocks in production e...
1. Apache server installation and configuration y...
This article example shares the application code ...
Table of contents Preface 1. Trigger Overview 2. ...
environment Host IP 192.168.0.9 Docker version 19...
CocosCreator version 2.3.4 Dragon bone animation ...
Table of contents 1 Conceptual distinction 2 Case...
1. Dynamically create objects There are two ways ...
1: Understand the meaning of address rewriting an...
Preface I believe everyone is familiar with addin...
Zabbix server environment platform ZABBIX version...
Application example website http://www.uhuigou.net...
Table of contents Preparation Deployment process ...