IE Conditional Comments and non-IE browsers

Recenlty I faced an issue on a website where a Lightbox Javascript plugin didn’t worked in Internet Explorer 9 and 10, but it worked perfectly in all other version of IE below version 9 and all non-IE browsers. In IE 9 and 10, when the plugin was loaded and the user clicked anywhere on the page, the whole page turned black and the website became unusable.

I only could work on the live website, so I wanted to do a quick fix by disabling the Lightbox plugin in IE 9 and above, and then find a better way to fix it. I started by addinig some conditional comments to load the plugin’s Javascript code only for versions of Internet Explorer below version 9:

<!--[if lt IE 9]>

Here is some code.

<![endif]-->

The problem with this fix is that the other non-IE browsers like Chrome/Firefox for example will consider those lines above as simple comment lines, thus the Javascript files for the Lightbox plugin are not loaded at all. I did some research and found a workaround which does the trick, and now the Lightbox plugin files are loaded for all non-IE browsers and all versions of IE below version 9 (for IE9 and 10, the plugin’s files are not loaded at all) :


<!--[if lt IE 9]> <!-- -->

Here is some code.

<![endif]-->