Recently in Masaki JS World's shortest IE browser to judge the code of the article, see only 6byte to judge ie and non ie method. The code is as follows:
<script> if (!+[1,]) alert ("This is IE browser"); Else alert ("This is not IE browser"); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
In fact, there are many ways to judge, mostly according to the characteristics of the browser.
For example, the library prototype method is:!! (Window.attachevent && navigator.userAgent.indexOf (' Opera ') = = 1). is based on IE support window.attachevent to add listening events, not IE use Window.addeventlistener to add listening events to judge. Navigator.userAgent.indexOf (' Opera ') = = 1 is because the Opara browser can be disguised as ie. if!! (window.attachevent) is true, ie; conversely, if!window.addeventlistener is true, it can also be judged as ie.
EXT is using! " 1 "[0], he uses IE cannot use the array subscript to access the character of the string to judge. There seems to be a problem under the IE8.
In!+[1,] before being discovered, the expression that determines IE shortest is!+ "\v1". It utilizes the feature that IE does not support vertical tabs.
Previously there was a common method of document.all, because opera browser can be disguised as ie. Can write like this:!! (document.all && navigator.userAgent.indexOf (' Opera ') = = 1).
There are many, first remember these several, easy to consult when working.
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)