Detect IE browser by using JavaScript

Posted huanlegu0426

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Detect IE browser by using JavaScript相关的知识,希望对你有一定的参考价值。

 1 <script>
 2 function detectIE() {
 3     var ua = window.navigator.userAgent;
 4 
 5     var msie = ua.indexOf(‘MSIE ‘);
 6     if (msie > 0) {
 7         // IE 10 or older => return version number
 8 //                return parseInt(ua.substring(msie + 5, ua.indexOf(‘.‘, msie)), 10);
 9         return true;
10     }
11 
12     var trident = ua.indexOf(‘Trident/‘);
13     if (trident > 0) {
14         // IE 11 => return version number
15 //                var rv = ua.indexOf(‘rv:‘);
16 //                return parseInt(ua.substring(rv + 3, ua.indexOf(‘.‘, rv)), 10);
17         return true;
18     }
19 
20     var edge = ua.indexOf(‘Edge/‘);
21     if (edge > 0) {
22         // Edge (IE 12+) => return version number
23 //                return parseInt(ua.substring(edge + 5, ua.indexOf(‘.‘, edge)), 10);
24         return true;
25     }
26 
27     // other browser
28     return false;
29 }
30 
31 function alert_browser_version() {
32     if(detectIE()){
33         alert("Browser Error:\nWe are strongly recommend you visit the website via Chrome or Firefox instead of IE.");
34         window.location.href = "http://hkw20016704.hbap.adroot.hsbc:8000/cr/index/";
35         return false;
36     }
37 }
38 </script>

 

<body onload="alert_browser_version()">
....
</body>

  

以上是关于Detect IE browser by using JavaScript的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript Browser Detect Lite v2.1

python flask detect browser language

如何将 FEATURE_BROWSER_EMULATION 设置为 IE8 模式?

c# Console application Open/Get Url by Browser

(浏览器选项卡)Browser Tab

IE8 Browser Bootstrap 仅在响应模式下工作 [重复]