Summary of several judgment methods for JS ie non-ie browsers

Source: Internet
Author: User

Recently, in the article about the shortest IE browser judgment code of situ zhengmei Js in the world, we can see that there are only 6 bytes of methods for judging IE and non-ie. Its Code As follows: <textarea id="runcode83828"><Br/></textarea>
[Ctrl + A select all Note: If you need to introduce external JS, You need to refresh it to execute]

In fact, there are many judgment methods, mostly based on the characteristics of the browser.

For example, the method for database prototype is :!! (Window. attachevent & navigator. useragent. indexof ('Opera ') ===- 1 ). It is determined by IE's support for window. attachevent to add listening events. It is not determined by IE's use of window. addeventlistener to add listening events. Navigator. useragent. indexof ('Opera ') =-1 is because the opara browser can pretend to be Ie. If !! (Window. attachevent) is true, that is, ie; otherwise, if! Window. addeventlistener is true, and can be determined as IE.

EXT is used! "1" [0], which is determined by the feature that IE cannot use array subscript to access the string. It seems that there is a problem in IE8.

In! + Before [1,] is not found, the minimum expression for determining IE is! + "\ V1". It uses the features that IE does not support vertical tabs.

In the past, there was another common method: Document. All, because the Opera Browser can pretend to be Ie. You can write it like this :!! (Document. All & navigator. useragent. indexof ('Opera ') ===- 1 ).

There are many other items, which can be easily viewed at work.

1. + [1,]

2 .! + "\ V1"

3 .!! (Window. attachevent & navigator. useragent. indexof ('Opera ') ===- 1)

4 .!! (! Window. addeventlistener & navigator. useragent. indexof ('Opera ') ===- 1)

5 .!! (Document. All & navigator. useragent. indexof ('Opera ') ===-1)

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.