Skip to content

davesmiths/isIE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

isIE

JavaScript to detect Internet Explorer and it's version number

Yep, another way to do it and hopefully compliments the methods already out there, which include html’s conditional classes, object detection, dynamically adding conditional comments and user agent sniffing (for the brave or naughty).

What I like about this script is it's just JavaScript, can be run immediately and anywhere in the HTML, and is small.

Demo

Download and use the demo or try dave-smith.info/GitHub/isIE/demo/

Compatibility

IE version and compatibility mode correctly identified in:

  • 10 (Win8)
  • 9 (Win7 SP1)
  • 8 (WinXP SP3)
  • 7 (Win Vista SP2)
  • 6 (WinXP SP3)

If a browser or version isn't mentioned here then it hasn't been tested; more tests welcomed.

How it works

isIE creates two variables:

  • isIE: The browser major version number
  • isIEmode: The compatibility mode major version number

isIE is calculated using Conditional Compilation, which could roughly translate as IE conditional comments in JavaScript. The key of which is @_jscript_version, a variable providing a version number which can be used to identify IE versions, see Conditional Comments in JScript.

By default isIE is false, so all non-IE browsers get false. Only browsers that know Conditional Compilation comments set isIE to something else.

When IE is detected isIE is set to the major version number, for example IE 10 will set isIE = 10. The only exception to this is for all IE lte 5.5 which sets isIE = 5.

In testing I found that isIE gives the browser version even if the compatibility mode is changed, for example if IE 10 is used in IE 7 mode, then IE 10 will be the detected version. Hence isIEmode is also created as knowing both may be useful.

isIEmode is calcaulated using the proprietry object document.documentMode. By default this is set to isIE and overridden with the compatibility mode major version number when document.documentMode exists.

Seen elsewhere

Thanks

There was a stackoverflow answer that mentioned Conditional Compilation and this got me started on the above, I can't find the stack again but I thank that person.

Created 2013 December 12

About

JavaScript to detect Internet Explorer and it's version number

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors