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//

Continue reading “Jscript Versions Reported By Major Versions of Internet Explorer (For Use With Conditional Compilation)”