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>

  

posted @ 2017-07-19 16:38  huanlegu0426  阅读(228)  评论(0编辑  收藏  举报
returnTop $(function(){ $('#returnTop').click(function () { $('html,body').animate({ scrollTop: '0px' }, 800); returnfalse; }); });