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 >
....
</body>

  

时间: 2024-11-05 17:43:59

Detect IE browser by using JavaScript的相关文章

Browser Security-css、javascript

层叠样式表(css) 调用方式有三种: 1 用<style> 2 通过<link rel=stylesheet>,或者使用style参数. 3 XML(包括XHTML)可以通过<?xml-stylesheet href=...?> 浏览器进行解析的时候会先HTML解析再做CSS解析,所以下面的代码会出错: <style> some_descriptor { background: url("http://www.example.com/</s

python flask detect browser language

python flask detect browser language No problem. We won't show you that ad again. Why didn't you like it? Uninteresting Misleading Offensive Repetitive Other Oops! I didn't mean to do this.          up vote-2down votefavorite I need to get the browse

comp.lang.javascript FAQ [zz]

comp.lang.javascript FAQ Version 32.2, Updated 2010-10-08, by Garrett Smith FAQ Notes 1 Meta-FAQ meta-questions 1.1 Which newsgroups deal with javascript? 1.2 What questions are on-topic for comp.lang.javascript? 1.3 What should I do before posting t

JavaScript - 客户端检测

<JavaScript高级程序设计>上down的,检测呈现引擎.平台.操作系统.移动设备.游戏系统 的检测脚本. var client = function(){ //rendering engines var engine = { ie: 0, gecko: 0, webkit: 0, khtml: 0, opera: 0, //complete version ver: null }; //browsers var browser = { //browsers ie: 0, firefox

关于JavaScript测试工具:QUnit, Jasmine, MoCha

在进行前端开发过程中,在某些场景下,需要通过编写单元测试来提高代码质量.而JavaScript常用的单元测试框架有这几个:QUnit, Jasmine, MoCha.下面就基于这三个工具,简单做一比较: 1. QUnit QUnit是一个JavaScript单元测试框架. 它是个强大,容易使用和上手的JavaScript单元测试框架.它被用于进行 jQuery, jQuery UI and jQuery 移动工程的测试,以及其他通用的JavaScript代码测试. Features:- Simi

【JavaScript】笔记01——Making Stuff Happen???

While, generally speaking, HTML is for content and CSS is for presentation, JavaScript is for interactivity. 1.从HTML到JavaScript,像下面这样: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </

JavaScript之基础-1 JavaScript(概述、基础语法)

一.JavaScript 概述 JavaScript 概念 - JavaScript 是一种运行于 JavaScript解释器/引擎中的解释型脚本语言 - JavaScript 解释器作为JS脚本的运行环境,有如下两种呈现方式 - 独立安装的 JavaScript 解释器; - 嵌入在浏览器内核中的 JavaScript 解释器; - 目前 PC .平板.手机.机顶盒中安装的主要浏览器全部支持JavaScript JavaScript 发展史 - 1992年,Nombas公司为自己的CEnvi软

Exploring JavaScript

When learning a new programming language, it's important to try the examples in the book, and then modify them and try them again to test your understanding of the language. To do that, you need a JavaScript interpreter. Fortunately, every web browse

JavaScript覆盖率统计实现

主要需求 1. 支持browser & nodejs 由于javascript既能够在浏览器环境执行,也能够在nodejs环境执行,因此须要能够统计两种环境下单元測试的覆盖率情况. 2. 透明.无缝 用户写单元測试用例的时候,不须要为了支持覆盖率统计多写代码,之前写的用例无需改动就能够直接统计覆盖率情况. 原理 javascript覆盖率的相关文章比較少.以下的图是通过阅读开源javascript覆盖率工具istanbul及开源測试框架Karma的覆盖率插件karma-coverage得出的.