In fact, there are a lot of judgment methods, mostly based on the characteristics of the browser, here a simple arrangement, you can refer to the need of friends. 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. The Code is as follows:
Script if (! + [1,]) alert ("this is Internet Explorer"); else alert ("this is not Internet Explorer"); script
[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)