18

My programmer is on vacation so I need your help! I discovered a page that has a bug for IE users. I want to redirect all IE users to a different page.

How can I do this? I searched all through Google and Stackoverflow and cannot find an answer. (I found some scripts, and tried them, but none worked).

6
  • 3
    maybe it will be easier/better to fix ie bug. You can try to ask separate question about that bug
    – Igor Milla
    Oct 3, 2011 at 16:10
  • Is PHP an option? Because a javascript solution will only work if javascript is enabled...
    – Dennis
    Oct 3, 2011 at 16:18
  • @Dennis, I've suggested a non-JS solution as an answer below
    – ChrisW
    Oct 3, 2011 at 16:23
  • @ChrisW: +1 for it. But you can also disable the META REFRESH. And there's browsers that just don't respect the tag. For instance, it doesn't work in Google Chrome.
    – Dennis
    Oct 3, 2011 at 16:27
  • @Dennis - thanks, I didn't realise Chrome didn't respect it!
    – ChrisW
    Oct 3, 2011 at 16:36

8 Answers 8

48

Try:

<!--[if IE]>
<script type="text/javascript">
window.location = "http://www.google.com/";
</script>
<![endif]-->
5
  • I didn't think of doing it that way! Oct 3, 2011 at 16:11
  • HALLELUJAH!!! That worked! Thank you so much - I knew there was a simple way to do it!
    – Gregg
    Oct 3, 2011 at 16:15
  • @Gregg: Please mark as answer the post that solved your problem. Oct 20, 2011 at 0:10
  • 1
    Note it's for IE9 or less. May 6, 2021 at 8:03
  • Would I put this code in the <head></head> tags? Apr 23, 2022 at 2:46
37

Or, a non-JS solution, put the following in your head section:

<!--[if IE]>
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.google.com">
<![endif]-->
2
  • Great, I was looking for non JS solution :) Don't you know if there is any way to redirect it before main page load. IE8 shows the main index page for a second and then redirects.
    – egurb
    Sep 18, 2015 at 13:01
  • it looks better, and lighter. Jan 13, 2017 at 12:18
7

A reminder that the [if IE] solution does not apply to IE 10 or greater. This can be very annoying for "features" that have not been fixed by IE 10. I am going to try the php and java solutions and re-comment.

7

I put this in header and it works for all IE versions:

<!-- For IE <= 9 -->
<!--[if IE]>
<script type="text/javascript">
    window.location = "https://google.com";
</script>
<![endif]-->

<!-- For IE > 9 -->
<script type="text/javascript">
    if (window.navigator.msPointerEnabled) {
        window.location = "https://google.com";
    }
</script>
0
3

For Internet Explorer 10 this one works well

<script type="text/javascript">
   if (navigator.appName == 'Microsoft Internet Explorer')
   {

      self.location = "http://www.itmaestro.in"

   }
</script>
2

Server-side solution using PHP that's guaranteed to work on all browsers:

<?
if ( preg_match("/MSIE/",$_SERVER['HTTP_USER_AGENT']) )
        header("Location: indexIE.html");
else
        header("Location: indexNonIE.html");
exit;
?>
8
  • 3
    Not totally guaranteed to work, the HTTP_USER_AGENT can be edited (e.g. addons.mozilla.org/en-US/firefox/addon/user-agent-switcher
    – ChrisW
    Oct 3, 2011 at 16:33
  • 1
    Apparently, there is a way (pctools.com/guides/registry/detail/799, although I haven't tested this), although I doubt many people (especially IE users!) would actually ever bother to do this!
    – ChrisW
    Oct 3, 2011 at 16:40
  • 1
    Well, I guess using a local proxy would also be an option. But equally unlikely for most people.
    – Dennis
    Oct 3, 2011 at 16:48
  • 1
    All this is assuming that Gregg is using PHP in the first place. Oct 3, 2011 at 17:42
  • 1
    My IE11 default user agent's string is "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" (WTF IE) , so this doesn't work for it. And anyways, you can easily change the user string there, so this isn't a guaranteed solution.
    – Spaceploit
    Jul 2, 2015 at 20:22
0

Support for conditional comments has been removed in Internet Explorer 10 standards

I'm use this dirty hack for redirecting IE10+ users

<script type="text/javascript">
    var check = true;
</script>
<!--[if lte IE 9]>
<script type="text/javascript">
    var check = false;
</script>
<![endif]-->
<script type="text/javascript">
    if (check) {
        window.location = "page_for_ie10+.html";
    }
</script>
0

js code:

<script>if (/*@cc_on!@*/false || (!!window.MSInputMethodContext && !!document.documentMode)){window.location.href="https://....html";}</script>

You can also use this Boycott-IE:upgrade-your-browser

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.