The shortest JS to determine whether it is IE6 (IE writing method)

The shortest JS to determine whether it is IE6 (IE writing method)

Commonly used JavaScript code to detect which version of IE the browser is, including whether it is the most extremely hated IE6 identification and detection.


Copy code
The code is as follows:

var isIE=!!window.ActiveXObject;
var isIE6=isIE&&!window.XMLHttpRequest;
var isIE8=isIE&&!!document.documentMode;
var isIE7=isIE&&!isIE6&&!isIE8;
if (isIE){
if (isIE6){
alert("ie6");
}else if (isIE8){
alert("ie8");
}else if (isIE7){
alert("ie7");
}
}

Then there is a slightly shorter js method to determine whether it is IE:
This seems to use the conditional compilation (or conditional comment) unique to JScript in IE to distinguish IE from non-IE (the IE/non-IE here refers to the kernel, and browsers with IE as the kernel will be regarded as IE)


Copy code
The code is as follows:

var ie = 0/*@cc_on+1@*/;

The shortest js code to judge IE or non-IE is only 7 bytes:


Copy code
The code is as follows:

var ie = !+'\v1';

In January 2010, a Russian took advantage of the difference between IE and standard browsers in processing array toString methods and perfectly completed the IE browser detection with only 6 bytes:


Copy code
The code is as follows:

var ie = !-[1,];

Using these findings, we can write code that is shorter. Now, the detection of whether it is IE6 can actually be written as:


Copy code
The code is as follows:

var ie6=!-[1,]&&!window.XMLHttpRequest;

The previous long and cumbersome analysis of navigator and the regular comparison method, the following JS method is more efficient!

<<:  Detailed explanation of triangle drawing and clever application examples in CSS

>>:  An article to help you understand Js inheritance and prototype chain

Recommend

Solution to 1290 error when importing file data in mysql

Error scenario Use the mysql command in cmd to ad...

Summary of Binlog usage of MySQL database (must read)

I won't go into details about how important b...

Detailed steps for installing JDK and Tomcat on Linux cloud server (recommended)

Download and install JDK Step 1: First download t...

Negative distance (empathy) - iterative process of mutual influence

Negative distance refers to empathy. Preface (rai...

How to use the concat function in mysql

As shown below: //Query the year and month of the...

Detailed explanation of storage engine in MySQL

MySQL storage engine overview What is a storage e...

Detailed explanation of mysql execution plan id is empty (UNION keyword)

Introduction During the work process, slow querie...

How to create a file system in a Linux partition or logical volume

Preface Learn to create a file system on your sys...

In-depth analysis of Flex layout in CSS3

The Flexbox layout module aims to provide a more ...

Vue component to realize carousel animation

This article example shares the specific code of ...

How to display TIF format images in browser

The browser displays TIF format images Copy code T...

In-depth explanation of the locking mechanism in MySQL InnoDB

Written in front A database is essentially a shar...

A complete list of common Linux system commands for beginners

Learning Linux commands is the biggest obstacle f...