3

I found out that my javascript-intensive web site doesn't work reliably (or at all) in IE9.

It works, (usually, but not always) with the compatibility mode meta tag in the header, but I just want to build a page that I know will work well in IE9 and then have the usual page redirect to it when IE9 is detected. The usual page is fine in IE 7 and 8 (and every other browser I've tried it on).

Can anyone give me some javascript that will do that? Thank you!

Here's my usual page:

http://ianmartinphotography.com/test-site/test/

ian_6500
  • 358
  • 2
  • 10
  • 21
  • 1
    Your site gets JavaScript errors in Chrome. You might want to check into that. – Pointy Sep 13 '11 at 19:25
  • Found this, but I think I prefer browser functionality detection in retrospect. See: http://stackoverflow.com/a/14835682/2140998 – Stuart Watt Sep 22 '15 at 16:56

2 Answers2

18

The simplest way would be to use IE Conditionals.

Note: IE10 and beyond have removed support for this feature. For modern browsers the widely accepted way of conditionally displaying content for compatibility purposes is using feature detection. Modernizr is a popular library built for handling feature detection.

For example:

<!--[if IE 9]>
<script type="text/javascript">
    window.location = "http://www.ie9version.com";
</script>
<![endif]-->

Examples from the conditional site:

<!--[if IE]><p>You are using Internet Explorer.</p><![endif]-->
<![if !IE]><p>You are not using Internet Explorer.</p><![endif]>

<!--[if IE 7]><p>Welcome to Internet Explorer 7!</p><![endif]-->
<!--[if !(IE 7)]><p>You are not using version 7.</p><![endif]-->

<!--[if gte IE 7]><p>You are using IE 7 or greater.</p><![endif]-->
<!--[if (IE 5)]><p>You are using IE 5 (any version).</p><![endif]-->
<!--[if (gte IE 5.5)&(lt IE 7)]><p>You are using IE 5.5 or IE 6.</p><![endif]-->
<!--[if lt IE 5.5]><p>Please upgrade your version of Internet Explorer.</p><![endif]-->

<!--[if true]>You are using an <em>uplevel</em> browser.<![endif]-->
<![if false]>You are using a <em>downlevel</em> browser.<![endif]>

<!--[if true]><![if IE 7]><p>This nested comment is displayed in IE 7.</p><![endif]><![endif]-->
Bengel
  • 1,043
  • 7
  • 12
  • And perhaps a meta redirect inside a ` – sdleihssirhc Sep 13 '11 at 19:27
  • Okay, that looks nice and simple--if I just want to redirect for IE, all versions, then I'd have <![if IE ]> ? Thanks! – ian_6500 Sep 13 '11 at 20:01
  • Yep! I'll throw some more examples from the page in the answer. – Bengel Sep 13 '11 at 21:14
  • Hmmm... It's redirecting in all browsers, not just IE... Here's what I've pasted right below the opening head tag: <![if IE 8> <![endif]> and here's the page, but it will most likely redirect on ya...http://ianmartinphotography.com/test-site/test/newcurveredirect.html Thanks for your help! – ian_6500 Sep 14 '11 at 20:49
  • 1
    I just updated the answer. They need to be commented conditional comments. instead of <![if IE 9]><![endif]>. – Bengel Sep 14 '11 at 20:59
  • 1
    @Bengel, can I a redirect for more than one, say, IE 6, IE 7 and IE 8? What would that look like? – ian_6500 Sep 14 '11 at 21:23
  • Yep, its flexible. For example if you want to redirect on IE8 or lower it would look like: – Bengel Sep 14 '11 at 21:31
  • 1
    Just note this is not working for IE 10. If you need a solution for it, check this post: http://stackoverflow.com/questions/19502040/if-ie-conditionals-not-working – Asterius Sep 23 '14 at 12:52
-1
<script LANGUAGE="JavaScript"> 
<!-- 

  if( navigator.appName.toLowerCase().indexOf("microsoft") > -1 || 
      navigator.userAgent.toLowerCase().indexOf("msie") > -1 ) { 
    window.open("http://www.pobox.com/~qed/windoze.html", "Windoze",
"dependent=no,titlebar=no,scrollbars=yes" ); 
  } 

// Paul Hsieh 
// qed at pobox dot com 
// --> 
</script>

Source: http://www.cexx.org/snicker/nomsie.htm