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

Docker deploys Mysql, .Net6, Sqlserver and other containers

Table of contents Install Docker on CentOS 8 1. U...

Vue uses custom instructions to add watermarks to the bottom of the page

Project Scenario Add a custom watermark to the en...

MySQL 8.0.17 installation and usage tutorial diagram

Written in front In the past and in the current p...

How Web Designers Create Images for Retina Display Devices

Special statement: This article is translated bas...

A simple method to regularly delete expired data records in MySQL

1. After connecting and logging in to MySQL, firs...

Implementation of breakpoint resume in vue-video-player

In a recent project, I needed to implement the fu...

Vue's Render function

Table of contents 1. Nodes, trees, and virtual DO...

The best way to start a jar package project under Centos7 server

Preface Everyone knows how to run a jar package o...

MySQL partition table is classified by month

Table of contents Create a table View the databas...

Introduction to new ECMAscript object features

Table of contents 1. Object properties 1.1 Attrib...

How to use binlog for data recovery in MySQL

Preface Recently, a data was operated incorrectly...

How to run top command in batch mode

top command is the best command that everyone is ...