Jscript Versions Reported By Major Versions of Internet Explorer (For Use With Conditional Compilation)

Conditional Compilation is a handy, Internet Explorer specific method for forking bits of JavaScript. The nice thing about it is that real browsers don’t notice it at all. It just looks like a comment block to any non-IE browser. Which saves the rest of the world from even having to if (IE) { } else { } . I like that.

Anyway, we use it to fix some of IE’s shortcomings. One standard pattern is using it to fake the :hover pseudo-class on inputs in IE6. Something like this:

//IE6 HOVERS simplified// //this would be a bit different in protection //but you can see the idea /*@cc_on @*/
/*@if (@_win32)
var inputElements = document.getElementsByTagName("input");
var test = inputElements.length;
for (var i=0; i<test; i++) {
      if (inputElements[i].getAttribute("type") == "submit"){
            inputElements[i].onmouseover = inputElements[i].onfocus =  function(){
                  addClass(this, "hover");
            }
            inputElements[i].onmouseout = inputElements[i].onblur = function(){
                  removeClass(this, "hover");
            }
      };
}; /*@end @*/
//END IE6 HOVERS//


Anyway, we were looking to use conditional compilation to add support for the :after pseudo-element to pre IE8 browsers and we were wondering what the different viewing modes of IE8 report when faced with Conditional Compilation tests. I put together a quick test to see what the answer was. I then decided to extend the test to a full survey of Internet Explorer browsers.

This is the test page.. It will be meaningless in any browser other than Internet Explorer.

Here’s the test code:

<!DOCTYPE html>
<html>
<head>
<title>conitional compilation test</title>
</head>
<body>
<script type="text/javascript">
/*@cc_on
document.write("version: "+@_jscript_version +" build: " +@_jscript_build);
@*/
</script>
</body>
</html>

And the results:

Internet Explorer Version JScript Version JScript Build
8 (Standards Mode) Windows XP 5.8 22886
8 (IE7 Mode) Windows XP 5.8 22886
8 (Quirks Mode) Windows XP 5.8 22886
5.2. Mac OSX 10.4 5 3715
5.0 Windows 2000 Professional 5.1 5907
5.5 Windows 2000 Professional 5.5 6330
6.0 Windows 2000 Professional 5.6 6626
6.0 Windows XP 5.6 8820
7.0 Windows XP 5.7 5730
7.0 Windows Vista 5.7 6000
8.0 Windows Vista 5.8 18702
8.0 Windows 7 5.8 1635

As you can see the JScript version is reported as 5.8 no matter what mode IE8 is actually running in. Which sucks since individual users, Microsoft themselves (by way of their compatibility blacklist) and system administrators can force the browser into modes other than IE8 Standards. Which means you could have a visitor forced into IE7 mode and your conditional compilation code will be trying to execute based on the IE8 Standards mode.

Fun times.

Filed under: knowledge is power.

Leave a Reply

Your email address will not be published. Required fields are marked *