Conditional Comment for 'Except IE8'

Conditional comment for 'Except IE8'?

I can think of a trick. Set a variable inside the IE conditional tag and include your JS code if that variable isn't set.

<script>
var ie8 = false;
</script>

<!--[if IE 8]>
<script>
ie8 = true;
</script>
<![endif]-->

<script>
if (ie8 == false) {
// any code here will not be executed by IE 8
alert("Not IE 8!");
}
</script>

Conditional Comment to run for all browsers except IE 8 and below

The trick explained there would work just as well for external scripts — set a "this browser is old" flag in a conditional-commented inline script, and have your external scripts check for that flag.

If you mean to conditionally include entire script files, your best bet would probably be a script that browser-sniffs and dynamically includes the appropriate files. Otherwise, you could use downlevel-revealed conditional comments (thanks, bobince!).

Do something except in Internet Explorer 8 and lower?

I found an answer, and it's pretty simple:

if ( parseFloat((navigator.userAgent.match(/MSIE ([0-9]+[\.0-9]*)/)||[0,9])[1])>=9 ) {
//do something for all browsers and IE9+
} else {
//do something only for IE8 and lower
}

Explanation:
The navigator.userAgent.match(/MSIE ([0-9]+[\.0-9]*)/) will return an array includes the whole string in index 0, and the version in index 1. If the match not found, it will return NULL.

Once the phrase returns a NULL, it will use the next operand [0,9], with the version 9 in index 1 (the lowest version of IE you are looking for).

Then, I take the value of index 1 and checking if it's greater or equal to 9.

So what does it means?

It means that every browser that is not IE will pass the IF, because the match will always return NULL, it will take the default array and finally check if 9>=9, which is alway true.
If the browser is IE, it will take the actual version of the browser, and will check it. In that case all IE9+ versions will pass the IF statement, and for the rest it will fail.

Hope it clear enough.

HTML if not IE 8 or lower

I'm not sure if this is valid syntax, but it does work in my case, so I'll post it here:

<!--[if gte IE 9]><!-->
<canvas width="200" height="200"></canvas>
<!--<![endif]-->

This will target IE>=9 and other browsers, and IE<9 will ignore the content.

CSS conditional comments for other Browsers except IE?

Check out the CSS Browser Selector plugin. I use it on my site, you basically just write the CSS and tell which browser you want it to target. I use it on my site and it works great!

Hope it helps.

Disable script if user browsing using IE8

Try this.

For disabling script for IE 8

<!--[if !(IE 8)]><!-->
<script src="path/to/external/script"></script>
<script>
// your inline script goes here
</script>
<!--<![endif]-->

For disabling script for IE 8 and above

<!--[if !(gte IE 8)]><!-->
<script src="path/to/external/script"></script>
<script>
// your inline script goes here
</script>
<!--<![endif]-->

Read bobince's answer: Conditional comment for 'Except IE8'?



Related Topics



Leave a reply



Submit