Javascript Method for Determining the browser type _ javascript skills

Source: Internet
Author: User
This article introduces how to judge the browser type by js. If you need it, refer to the code below:

The Code is as follows:


Var isIE = !! Window. ActiveXObject;
Var isIE6 = isIE &&! Window. XMLHttpRequest;
Var isIE8 = isIE &&!! Document.doc umentMode;
Var isIE7 = isIE &&! IsIE6 &&! IsIE8;
If (isIE ){
If (isIE6 ){
Alert ("ie6 ″);
} Else if (isIE8 ){
Alert ("ie8 ″);
} Else if (isIE7 ){
Alert ("ie7 ″);
}
}


The above is a common JavaScript code used to detect which version of the browser is IE.

In January 1 this year, the Russians used the difference between IE and the standard browser in handling the toString method of arrays, making perfect use of 6 bytes :! -[1,] checks whether the browser is an IE browser. The shortest code is :! + 7 bytes of "v1. Using these findings, we can also make our code shorter and more artistic. Check whether IE6 can be written

! -[1,] &! Window. XMLHttpRequest

This code is useful in actual use. Since it can be written in a shorter time, why not. Compared with the previously cumbersome analysis navigator, the regular expression comparison method is of course more efficient, and the code is more concise. In the JavaScript writing process, we should make full use of such features as || ,&&,! ,!! Such operators are not only in the case of if.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.