Advanced Search

View RSS Feed

molendijk

Automatic IE upgrades

Rate this Entry
A couple of days ago, I noticed that I have IE10 on my computer, although I did not install this latest IE-version myself. Apparently, Microsoft has started automatic upgrades of IE to its latest version(s).

So I wanted to know how my sites looked like with IE10 (I normally use Firefox). They looked normal, but the javascript on certain pages produced unwanted results that were not problematic until now (with IE7/8/9).

At first, I was unable to find out what caused the trouble. Then I remembered having read somewhere that support for conditional comments has been removed in IE10. So I removed the comments and replaced them with (javascript browser) sniffing lines and voilą: everything was fine again.

Here's the javascript I used (it seems reliable):
if(/*@cc_on!@*/false){} // if IE
if(/*@cc_on!@*/true){} // if not IE
if (ieversion==7){} // if IE7
if (ieversion>7){} // if IE8 and up
if (ieversion>=8) // if IE8 and up

etc.

For the ie-version lines I used the following script:
<script type="text/javascript">
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
{ //test for MSIE x.x;
var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
}
</script>


I hope this may be useful.

Submit "Automatic IE upgrades" to del.icio.us Submit "Automatic IE upgrades" to StumbleUpon Submit "Automatic IE upgrades" to Google Submit "Automatic IE upgrades" to Digg

Tags: None Add / Edit Tags
Categories
Uncategorized

Comments

  1. jscheuer1's Avatar
    There's a slightly more efficient (since IE 6 all IE versions are whole numbers, so we need not worry about the \.\d+ part any longer) and more standard (using RegExp.$# has been deprecated) way to test IE version in javascript:

    Code:
    var ievesion = /MSIE (\d+)/.exec(navigator.userAgent);
    ieversion = ieversion? ieversion[1] : false;
    However, since IE 10 is for the most part as compliant as any other modern browser, IE conditional comments can still be used in most cases. IE 10 will take the same path as - say, Chrome or the Fox.
  2. molendijk's Avatar
    Yes, you're right about the javascript. Thanks.
    As for the IE conditional comments, the problem I encountered was that with IE10, lines like
    Code:
    <!--[if IE]>
    <script>
    alert('hello')
    </script>
    <![endif]-->
    and
    Code:
    <!--
    <script>
    alert('hello')
    </script>
    -->
    are treated in exactly the same way (same result: no alert) unless we add a meta tag like:
    Code:
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">
    which we don't want in many cases.
  3. Beverleyh's Avatar
    My IE10 update rolled through a few days ago so I've been in a similar boat - nothing too twitchy, but a few conditional IE stylesheet tweaks that obviously now don't render.

    Easily fixed with some media queries plonked right back into my main stylesheets though...

    Code:
    @media screen and (min-width:0\0) {  /* IE9 and IE10 */  
    body { background:red; }
    }