Javascript not working on specific versions of IE

1k Views Asked by At

I've a rare issue with IE. I'm trying to create a page that launches this script when IE version is lower or equal than IE 8 (just a simple alert and a location). When I try to debug this html on IETester the alert only shows up on IE 5.5 and IE 6 but neither in 7 nor 8. What am I doing wrong?

<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<!--[if lte IE 8]>
    <script type="text/javascript">
        alert('Para poder usar Consumedia necesita tener instalada una version de Internet Explorer 9 o superior');
        window.location = "http://www.google.com";
    </script>   
<![endif]-->
</head>
<body>
</body>
</html>
2

There are 2 best solutions below

1
On BEST ANSWER

This is showing me the alert with native IE7.

It seems IETester might have a bug regarding conditional comments. See How do I make IE9 emulate IE7? for an alternative to IETester.

@Pekka has already commented on this matter a couple of times:

When multiple instances of Internet Explorer are installed (or active) on the same system, conditional comments will be resolved against the highest IE version available on the system

EDIT: Doesn't really add much, but I've got only IE7 installed, and it also shows the alert with IETester for IE <= 7.

5
On

Sory for my first answer, a don't realize the real problem.

Try to change the if statement:

<!--[if lt IE 9]>
    //Fires for IE8 and above
<![endif]-->

See the examples here: http://css-tricks.com/how-to-create-an-ie-only-stylesheet/