Detect & Redirect Script For Internet Explorer (IE)

NOTE: For anyone looking for the ability to detect and redirect based on IE version, you should check out this post. It uses conditional comments to detect IE versions and redirect accordingly.

dieie.jpgI hate Internet Explorer.

There, I’ve said it. Perhaps it will help you to understand why I sat down tonight and decided to ex-out the worst of the bunch, Internet Explorer 5.5 (and below).

It pains me, physically pains me, to open up Internet Explorer after having designed something using Firefox as my primary browser. Granted, with IE7, things have improved and my design often (in a very general way) resembles what it should. However, taking steps backwards in the IE pedigree, things quickly go from worse to craptastic.

So, I decided, this is my site, and I should be able to set the standards for what “type” of people I want on here (you all, of course, are welcome anytime). I went looking for a script to help me do it, and couldn’t find one (to be honest, I didn’t look very hard). I found several that would pick out your browser type, and version. But the problem with these is the version number generally only goes as high as 4 – which all IE5+ browsers are.

My parameters were simple. If the person visiting the site had any browser other than Internet Explorer – they could come in. And to show I’m not a complete brute, I decided that those visiting with IE7, and IE6 could also come and play. Otherwise you get redirected to a page that informs the visitor that they might want to reconsider their choice of Web surfing app.

If you just want the full code to make this happen, here you go:

Otherwise, lets put this together step by step.

Building the Script

First we need to open a blank text file (notepad or any plain text editor will do) to save as a Javascript file. Then, assign your variables:

var browser = navigator.appName
var ver = navigator.appVersion
var thestart = parseFloat(ver.indexOf("MSIE"))+1
var brow_ver = parseFloat(ver.substring(thestart+4,thestart+7))

The variables do the following:

  1. browser: Gets the browser type (IE, Netscape, etc.).
  2. ver: Gets the version string. A long string of info with various bits of goo in it.
  3. the start: We need this number for the next part – trust me.
  4. brow_ver: This is the IE version number (generally 5.5, 6.0 or 7.0), converted from a string into an integer.

Next, we need to create an IF conditional that decides whether the browser type is Internet Explore, and checks if the IE version is less than 6**. And if it is, we need to tell the browser to redirect to a pre-created HTML file instead of displaying the site.

if ((browser=="Microsoft Internet Explorer") && (brow_ver < 6))

Implementing it

Then, simply make sure you have the redirectfile.html (or whatever page you wish to redirect the misguided and outdated user to) created. Save the text file as something.js (I like the name ifoldie.js, but that’s just me), and add the following line in between the <head></head> tags of your Web page:

<script type="text/javascript" src="">

And there you have it.

As you can see from my redirect page, I’ve also added the user a convenient way to upgrade to a better browser.

** This can be changed to either be more diligent or less on who it allows access. If you want to redirect all users of IE6 and below, simply change this to 7. Likewise, it can be changed to 5.5 or 5 (or any lower number) to allow a greater range of access.

Add comments for any questions or suggestions.

121 thoughts on Detect & Redirect Script For Internet Explorer (IE)

  1. Hey Jerry, yes, just change the “6” to a “7” and this will only allow IE browsers of version 7 or higher (should they decide to continue making the piece of junk) through.

  2. Ryan,
    Thanks great script!
    What if I wanted to add Firefox to this script with a redirect to a different page?
    Do i need to add another variable? and if so what would (ver.indexOf(“***”))+1 look like? and I’m assuming the if conditional would just need to be added with the ((browser=”Firefox”)&&(brow_ver

  3. Hey Jerry, you could modify it to redirect for Firefox. The browser type will be listed as “Netscape” though, as Firefox/Mozilla is a branch of the original Netscape.

    The tricky part is that this script cuts up the rather long Browser Version string to find out which actual version of IE you’re using. Check out this page. It has a script on it that displays your browser information.

    If you’re using Firefox (as I am), you’ll see a string similar to:
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070725 Firefox/

    I don’t have the time to work out the math on it, but you just need to adjust the code in my script to cut that string up to give what Firefox version you’re using.

    If you want to redirect ALL Firefox browsers, that’s quite easy. Just search the string for “Firefox” and if it returns true, redirect.

  4. since about 85% of the world uses ie, its best to have two websites, one compatable with ie and one with firefox, I know it sucks, but its the most pro way.

  5. Hey Erik, two Web sites isn’t really necessary – using IE’s conditional comments, adding alternative style sheets is a much better way to go about it. Just setting up secondary CSS rules to adjust for IE’s retardedness.

    However – I still like the script, as it’s my little way of informing the world that they’re using a stupid browser. 🙂

    • 85% don’t know that the browser they use is outdated, so why not make the java script common on every homepage, but those made for those in countrys without reliable internet and modern computers ? 🙂

  6. Pingback: China Blogging - Living in China, studying Chinese, web design and development. » Google Referrals: Detect readers using IE, guide them to install Firefox
  7. Ryan, the idea seems very silly to me. I like browsing the web with lynx (text based browser), what good is it for me to use firefox? Don’t force people to choose, just code to the right standards, prove that your site validates to wC3 standards and then let the browsers update to the international standards. For I have only one stylesheet, and zero hacks for IE, Safari or Firefox and it renders perfectly in all of them.

    Let the users choose whatever browser they want on their own! If people want a crap web experience then that is their own choice.

    • Even if you code to standards, older IE versions won’t run a lot of the animation javascripts that Adobe Egde generates. I’ve used them on my site, and anything but recent versions of IE just freeze up. IE didn’t even support an alpha layer in PNG’s until just recently. Pathetic!!!

  8. Hey Valehru, didn’t know you headed back to Ireland.

    I’m not forcing anyone to choose. You browsing in a text browser, someone browsing in Safari or Opera, or whatnot, are not going to notice anything different.

    The only people affected on this site are people using an old outdated browser (IE5.5 or less) – which happens to break your site as well btw.

    The problem with your solution is a single style sheet with no alternate stylesheet (or if absolutely needed, hacks) is not possible in a more complex design with lots of elements.

    For a personal site (such as this, or any of my other sites) I can choose to do things like this redirect, however for clients sites, it most definitely will require that it look good in IE and all the best coding to standards in the world isn’t going to solve certain problems with IE6 – still the most widely used browser.

    Not to look up your skirt, but you’re using an IE hack in your CSS for this very reason.

    I do agree 100% that users should be allowed to choose whatever browser they want – but browser creators need to start more strictly adhering to standards. Once that happens (and it could be only a year or two away), life for your average CSS designer, will be a helluva lot easier.

  9. Whoops, I had forgotten about that one. Must work on that CSS page a little more to get full compliance. Dammit. 😀

    Browser creators, looking at MS in particular, are never going to comply completely with all these standards. They way they see it is that they have the market share and that’s that.

    Personally I despise IE with a passion, unfortunately in my line of work IE development is required. I once had a spec from a US client who demanded complete compliance from IE 5 and IE 6. Quite a difficult task. Fortunately with machines designed with IE 5 as a core browser are now reaching the end of their life cycle and are being phased out.

  10. Exactly. I’m definitely not suggesting that people use this on the site’s of clients/businesses/etc. But for me, as I do both my own and “for hire” design, I just wanted this little script for my sites as they aren’t focused on business, and allow me to kindly kick people in the pants should they be using an out-dated browser.

    And in regards to compliance, you gotta hand it to the swell folks on the Firefox development crew, as according to the figures on that link I gave in my last comment, they’re edging out IE one dissatisfied user at a time – and they do a reasonable job of maintaining compliance.

  11. I’m not sure this works, I’m trying to block IE6 and below browsers because I refuse to stoop to the level of using hacks and filters. More people are using IE7 and at least IE7 follows CSS standards better than it ever has.
    I tested this script on a windows 2000 platform with IE6 and it didn’t redirect me to the page at all.

  12. Hey Darren, I feel your pain man. I’ve not tested this using W2K, but if you copy and pasted the code above, I just noticed that in the first section of code – setting up the variables – the quotes are fancy quotes, and that will screw stuff up. Double check that.

    An easy way to see if it’s working is to use Set it to IE 5.5 or less and put in and you’ll see how it’s intended to work.

  13. Ryan,

    That’s EXACTLY it- it works! I didn’t even notice I had fancy quotes in the code, I’m glad you caught that.

    Let me say that the code OFFICIALLY works for IE6 version browsers and below.

    I recently learned CSS and found it to be a true pain in the @$$ that in order to make a site look good on IE6 – you have to use all sorts of hacks and bug fixes. I’m with you Ryan. CSS is a standard and browsers should try following those standards or be rejected. I’m sure there will be people who disagree because 36% still use IE6 but it sure would be nice to see everybody up to speed on web standard compliant browsers. This way developers can focus on creating great web sites without having to pull out their hair trying to find the right hack, bug fix, or filter.

  14. ahha this is damend useful for me. I’m working on a site for a uni course. Complys fully with xhtml(strick)1.0 and fully with CSS3.0 (doesn’t comply with 2.0 because i use overflow-y: in my CSS)

    My page looks like crap on IE6 though, so i was looking for a redirect to either warn them that the page won’t work, or just not allow access until they upgraded

    Note: complys fully with the latest standards. Either way this piece of script is definatly going to be useuful to me.

  15. I’m about to give up, no matter what I do I does not work 🙁 this is what I’m writing:
    var browser = navigator.appName
    var ver = navigator.appVersion
    var thestart = parseFloat(ver.indexOf(”MSIE”))+1
    var brow_ver = parseFloat(ver.substring(thestart+4,thestart+7))
    if ((browser==”Microsoft Internet Explorer”) && (brow_ver

    if I delete all the var that has something to do with the version and just leave the var browser works, but no matter how bad I would like to reject IE users I can’t so I just want to reject the IE6 and lower users… help!

  16. Hey Nancy, it’s an issue with curvy quotes (”) – change them to straight (") quotes and you should be alright. Damn WP automatically changes them.

    Optionally, simply copy and paste the code directly from the .JS file.

  17. It worked!!!! 🙂 thank you very much, do you mind if I use some of your text from your oldie.html?. I love what it says and everything and I sure want people to use Firefox instead on IE, but I think my client will find it “aggressive”, but I want to use the same concept.

  18. @Nancy – glad it’s working. You are welcome to change any part of the script, text, or graphics to better suit your needs. I offer no copyright on any of it.

  19. Awesome script, when IE 6 (and older), simply fails to open strict DTD and latest WAI standard web sites. It’s good that Microsoft realised that their de facto standards does not work compared to W3C. IE7, and hopefully the upcoming IE8, works much better!

  20. Hi Ryan, thanks for this script, much appreciated.. I did notice in your comments that you were saying a better option would be to redirect to a different stylesheet instead which is what I would prefer doing. Care to enlighten us on how that would be done?

  21. Pingback: Using Conditional Comments to Catch IE | Dao By Design Blog
  22. Hey Kevin – check out the pingback between your comment and this one – wrote that sucker just for you 😉 (and because this blog desperately needed to be updated!).

  23. Great script, simple but perfect for I needed. I check my stats and still see that IE is most commonly used…sucks to be a developer 🙂

  24. Thank you!!! IE is the bane of my web existence. You have made my life so much easier!

  25. Awesome! thank you so much. I no longer feel as though my face is going to implode out utter frustration. that’s a good feeling.

  26. I found that I had to add an ‘=’ to the ‘brow_ver < 6’ to make it detect and redirect IE6.

    if ((browser==”Microsoft Internet Explorer”) && (brow_ver <= 6))

    Like that, in other words. Thanks a million for this script.

  27. Pingback: Hate Internet Explorer? Take a stand against IE6 browser | Dao By Design Blog
  28. Pingback: Internet Explorer: Matando diseños CSS | Asociación Libre de Ideas
  29. @Kiten: Simply throw it in between the HEAD tags usually found in the header.php file of your theme.

  30. Hi,

    Is it possible to redirect certain people to a firefox ready page? and all others to a IE ready page? Seems these two are the main browsers in the UK.

    Will this slow people down? and is it 100% relaible?


  31. Pingback: » Blog Archive » Internet Explorer redirect script
  32. Pingback: GirlyBlogger » Blog Archive » Internet Explorer: Matando diseños CSS
  33. Just want to let you know – love this script… Exactly what I was looking for (going to include in my new site). But I have to say, I agree with many people of having to create an alternate site for IE6, etc… So in my case I will be going that. Also, I agree with you – I HATE IE as well!

  34. Hi Ryan,

    Thanks for this script. I’m having success with the redirect, but my problem is that IE6 just keeps redirecting and redirecting and the actual never loads. It’s like the script saw it was IE6, said “send it over to /ie6/” and once /ie6/ started to load, the script tried to send the user to /ie6/ again, thus never actually loading the page.

    Any idea what might be going on? Many thanks.

  35. YEAH this script rocks, now I can redirect to a page that will say something like: “We support the death of IE 6”. I hope IE 6 users gets the point . Thanks man you look great

  36. Wow Ryan!! Thank you so much for the script. it works like charm. Great work! bye bye oldie!

  37. I don’t get it…the script works fin in IE simulators, but it does not distinguish between IE6 and IE7. It redirects both-regardless. I only need IE6 and below redirected, not 7 and and above. I’m not sure why it is not working…=(

  38. It’s me again…scratch that, it redirects ALL versions of IE…does not distinguish versions. Filters them all…as much as I hate Emperor Gates MicroCrap Exploder…some of the users of my site have this piece of junk as a browser, and I just want to weed out IE 6 and older-not all of them. Help please!!! I wonder if this is a Vista problem, another Microsoft Genius Product by the way…


  39. @JQuest – please see the note I’ve added to the top of the post. It was a comment I left on here a while ago, but as it’s burried in the comments, I realized I need to draw more attention to it.

    Basically, check this post. It’s a more efficient way of handling things.

  40. Ryan-you are the man!!! A simple fix; why did I not think about that!!! Works like a charm now!! Thanks!!! I will follow the cause-IE is goin’ down…

  41. Thanks for your script, one of my sites is now sending IE6 users to an advise page to get some newer stuff. I hated when, showing this site to people, I saw that wordpress just didn’t worked there. Maybe it’s WP issue, but I don’t seem to care.

  42. Hello Ryan,

    Just put this script on my website. Works fine. Cheers. Saved me having to redesign just for ie6 or lower. Amazingly, ie6 still has a 20% share of web users in 2010! its four years since ie7. The updates free people.

    Thanks as well for explaining how to use the script in a clear way, a rare talent for a web developer!

    Rock on.

  43. THANK YOU THANK YOU THANK YOU!!!!!!!! I HATE Internet Explorer too. This is what i needed.

  44. Awesome, am going to use this heaps. United we stand against corporate oppression.

  45. Pingback: Malcom McCutcheon » Blog Archive » Just Say No to Microsoft Internet Explorer
  46. Thank you very much, it is working. My site didn’t work at all in IE 4 5 and 6, so I needed this. From now on, i will probably use your code on most of the websites. Cheers

  47. Finally a script that works.
    I’ve tried so many and something always was going wrong.



  48. Thank you so much! The sample files seem to be gone but your instructions are thorough and I implemented my first (well, your’s really!) javascript.

  49. Hey man. Using your script – its ace! Just one thing, I’m getting feedback from some visitors who insist they’re using IE8 (the only IE I’ll permit) yet are still getting the redirect page. I can’t get to their machines to verify their claims but I’ve had this a couple of times so I’m inclined to think they’re telling the truth. Any ideas?

  50. Can someone post what I need to add to detect other old browsers too, such as Netscape?

  51. Hi Graham — sorry, those files fell off long ago, as this post is from back in 2007. As the note at the top of the post indicates, a better way of handling this is through conditional comments. I have updated the links though.

  52. I never usually post on things like this that I read, but this has just solved a massive problem for me.

    Taking out the the ‘&& (brow_ver < 6)' stage can enable you to redirect completely if IE and makes it much easier to weed out annoying IE bugs.

    Thanks a lot!

    • No problem Matt. Glad it helped. I still think conditional comments are a better way of handling IE bugs (see link at the top of the post), but glad to hear the script is still useful.

  53. Hey thank u dude,thanks!!!
    I always suffers due to MSIE, i will use this to fix problem, for the older version of IE,,,,,Bunch of thanks to u dude,…………..

  54. You’re a fuc**ng GENIUS my friend!
    This script is simply amazing!!

    THANK YOU very much for sharing it!

    Thank you!

  55. I’m coding some pages in HTML5 and Opera doesn’t support it anywhere close to Chrome, FF, Safari, or IE9. Can you show me how I could make this work for old IE and Opera?

    Thanks, Matt

  56. Hahaha!! you’re a star! I totally agree, anyone browsing with IE 6 or below.. yes 6!.. can either go get a decent browser, or get lost!.. good work.

  57. Years later and it still works great and is easy to understand. And, unfortunately STILL need to do this. Thanks

  58. How can you interface this in HTML? I am using Weebly site builder for a friend of mind, but still want to add this sort of thing.

  59. Muchas gracias !

    It took me a while to find this info… thanks you very much !

  60. Tremendous issues here. I am very glad to look your article. Thanks so much and I am looking forward to touch you. Will you kindly drop me a mail?

  61. Ini adalah blog yang sempurna bagi siapa saja yang ingin tahu tentang topik ini. Kau tahu begitu banyak hampir sulit untuk berdebat dengan Anda (tidak bahwa saya benar-benar ingin … HaHa). Anda pasti meletakkan putaran baru pada subjek thats telah ditulis selama bertahun-tahun. Hal-hal besar, hanya hebat!

  62. Hello there, I love your blog. Is there something I can do to receive updates like a subscription or some thing? I am sorry I’m not acquainted with RSS?

  63. Am trying to redirect IE 8 and below users to a static page. This seems not to work on joomla!

    and I HATE IE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    • It not working won’t have anything to do with Joomla. Joomla is just a platform. You will have to adjust the code though, as this script wasn’t designed for IE8. Should be fairly obvious how to do that.

      • It works, I patched it on the index file for the template in use, works pretty fine. Thanks

  64. Thanks for the code but i’m having trouble getting it to work.
    tryed it in the head tag and the body tag with no result.
    here is the code can you help?
    var browser = navigator.appName
    var ver = navigator.appVersion
    var thestart = parseFloat(ver.indexOf("MSIE"))+1 //This finds the start of the MS version string.
    var brow_ver = parseFloat(ver.substring(thestart+4,thestart+7)) //This cuts out the bit of string we need.

    if ((browser=="Microsoft Internet Explorer") && (brow_ver

  65. Here is another copy as i don’t think i gave you the whole lot last post. Again your help would be great – thank you.
    OLDIE – or Old IE. A script that finds the version of IE you're using,
    and redirects if lower than the set parameter.
    [[ Created by Ryan McLaughlin, ]]
    var browser = navigator.appName
    var ver = navigator.appVersion
    var thestart = parseFloat(ver.indexOf("MSIE"))+1 //This finds the start of the MS version string.
    var brow_ver = parseFloat(ver.substring(thestart+4,thestart+7)) //This cuts out the bit of string we need.

    if ((browser=="Microsoft Internet Explorer") && (brow_ver

  66. Desperate for an elegant IE forwarding fix like this but can’t seem to get it to work. Please help, up against a dead line on this non-profit site. Current site works in IE 9 but not less than.
    OLDIE – or Old IE. A script that finds the version of IE you're using,
    and redirects if lower than the set parameter.
    [[ Created by Ryan McLaughlin, ]]
    var browser = navigator.appName
    var ver = navigator.appVersion
    var thestart = parseFloat(ver.indexOf("MSIE"))+1 //This finds the start of the MS version string.
    var brow_ver = parseFloat(ver.substring(thestart+4,thestart+9)) //This cuts out the bit of string we need.

    if ((browser=="Microsoft Internet Explorer") && (brow_ver

  67. brilliant, thanks so much for this. so sick of hearing from people, hey your website doesn’t work, or loads very slow.. then I had to ask them if they use IE.. and wait for a reponse. while going in total panic mode if it could be something else. so time to make a redirect script for IE8 and older and have some peace of mind. they are planning IE10 now.. my god, how many versions do they need to make it somewhat as good most browsers out there.
    and then there’s bing..
    Microsoft… can we sue them for ruining so many people’s lives? please? 🙂

  68. Ha… this is great. All IE versions <100 (future proof!) get redirected to a "please update" page.

    Thanks for sharing!

  69. Your script works – first time. My client is using ie 8 and cannot see certain css and jquery elements. So now when he reviews the site he goes to a simpler version (just for him).

    A question … how can I redirect other browsers that do not work with css3, etc.

    firefox, safari are the 2 I am most concerned about

    thanks for your good work and sharing it

  70. hey guys…
    this looks cool. but i’ve another solution,
    since the latest upgrade of IE for winXP users is IE8, and for Win7 is IE9. i wrote something that would display a message to users using IE7 and below.
    Thus making them using the latest.
    i used jquery.
    Here is the code:

    html{ display: none ;}

    alert(‘Your Browser is Outdated, Please Upgrade To View Our Website.’);
    $(window).load(function() {
    var url = “”;

    lte means : Lower than or Equal

    just add this in your head i works.

  71. OK- Works fine, thanks (!!!!), waste no time anymore for conditional commands 😉 – But how we can include more old browser for the redirecting rule….

  72. Script that works for me:

    var ua = window.navigator.userAgent;
    var msie = ua.indexOf(“MSIE “);
    var verIE = -1;
    if (msie > 0)
    verIE = parseInt(ua.substring(msie + 5, ua.indexOf(“.”, msie)));
    verIE = 0;
    if (verIE 0) {
    window.location = “”;

  73. Pingback: Détecter et rediriger les versions d'Internet Explorer en utilisant JavaScript | IL Design - Conseils et Tutoriels

Say something...

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Return to Top ▲Return to Top ▲