Detect & Redirect Script For Internet Explorer (IE)
I 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 files to make this happen, just right-click and select Save Link As...:
ifoldie.js oldie.html warning.jpg
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:
- browser: Gets the browser type (IE, Netscape, etc.).
- ver: Gets the version string. A long string of info with various bits of goo in it.
- the start: We need this number for the next part - trust me.
- 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))
{
window.location="http://www.yourdomain.com/redirectfile.html";
}
//-->
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="http://www.yourdomain.com/ifoldie.js">
</script>
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.

Levi
awesome, thanks!
August 11, 2007 @ 1:53 am
Jerry Sparrow
If I want to re-direct a user with 6 or lower i assume i just need to change if conditional to… brow_ver
August 13, 2007 @ 11:26 pm
Ryan
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.
August 13, 2007 @ 11:36 pm
Jerry Sparrow
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
August 15, 2007 @ 11:54 pm
Ryan
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:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6
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.
August 16, 2007 @ 7:42 am
erik
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.
September 4, 2007 @ 2:33 pm
Ryan
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.
September 4, 2007 @ 4:16 pm
Snadowitz
Just what I have been looking for all these weeks – the dogs-danglies – simple and it works!!!
September 24, 2007 @ 5:21 pm
China Blogging - Living in China, studying Chinese, web design and development. » Google Referrals: Detect readers using IE, guide them to install Firefox
[...] was just reading Ryan’s post over at DaobyDesign about how he guides his readers to upgrade to at least internet explorer 6: My parameters were simple. If the person visiting the site had any browser other than Internet [...]
October 8, 2007 @ 10:35 pm
Valehru
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 beilabs.com 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.
October 11, 2007 @ 11:57 pm
Ryan
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.
October 12, 2007 @ 8:07 am
Valehru
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.
October 12, 2007 @ 6:19 pm
Ryan
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.
October 12, 2007 @ 7:46 pm
Tom
DONT WORK!!!
November 19, 2007 @ 10:33 pm
Ryan
DOES WORK!!!
DON’T YELL!!!
November 20, 2007 @ 12:07 am
Darren
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.
December 21, 2007 @ 12:05 pm
Ryan
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 http://ipinfo.info/netrenderer/index.php. Set it to IE 5.5 or less and put in daobydesign.com and you’ll see how it’s intended to work.
December 21, 2007 @ 9:48 pm
Darren
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.
December 21, 2007 @ 11:49 pm
wowfood
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.
April 7, 2008 @ 7:37 pm
Nancy
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!
April 10, 2008 @ 9:52 am
Ryan
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.
April 10, 2008 @ 10:52 am
Nancy
Thank you I’ll try tomorrow, I’m too tired now, I’ll let you know
April 10, 2008 @ 11:29 am
Nancy
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.
April 11, 2008 @ 8:59 am
Ryan
@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.
April 11, 2008 @ 9:12 am
Nancy
Thank you!!!!!!!!!!
April 11, 2008 @ 10:38 am
marcus
right on .. IE, UGH!
April 11, 2008 @ 5:05 pm
Morten René
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!
April 21, 2008 @ 6:08 am
Kevin
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?
May 23, 2008 @ 3:03 am
Using Conditional Comments to Catch IE | Dao By Design Blog
[...] while back I whipped up a little script to detect and redirect visitors if they were using an old version of IE. In the comments I went on to say that a more effective/professional way of handling IE users is [...]
May 23, 2008 @ 11:46 am
Ryan
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!).
May 23, 2008 @ 11:52 am
Kevin
Thanks Ryan! checking it out now…
May 23, 2008 @ 11:58 am
Mikolaj
Thanks a lot. IE is crap ;/
June 6, 2008 @ 1:32 am
D
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
June 6, 2008 @ 12:28 pm
kindred spirit
Thank you!!! IE is the bane of my web existence. You have made my life so much easier!
June 13, 2008 @ 2:44 am
Asinausk
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.
June 21, 2008 @ 4:22 am
Chris M.
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.
July 24, 2008 @ 12:23 am
Hate Internet Explorer? Take a stand against IE6 browser | Dao By Design Blog
[...] of the first posts I wrote on this blog was a tiny little script that detects whether your visitor is using a particular version (or less) of Internet Explore… and then redirects them to a page explaining that they should get their ass in gear and get a [...]
September 18, 2008 @ 4:54 pm
Shan
Thank you Ryan, super useful.
September 24, 2008 @ 4:10 am
Ryan
Hey Shan, cheers.
NOTE: For anyone looking for the ability to detect and redirect based on IE version, you might be interested in the latest post on this blog. It essentially does a more subtle (and easier to implement) IE detection using conditional comments.
September 24, 2008 @ 8:46 am
Internet Explorer: Matando diseños CSS | Asociación Libre de Ideas
[...] Firefox? La capacidad de arruinar un increíble diseño CSS, nada más. Como escribió Ryan en Dao by Design hace tiempo, es realmente doloroso crear un diseño en Firefox, que luego va a lucir desastroso en [...]
September 28, 2008 @ 3:05 pm
Kiten
Hello, great script, thanks!
How to insert code into Wordpress blog ?
October 3, 2008 @ 6:14 am
Ryan
@Kiten: Simply throw it in between the HEAD tags usually found in the header.php file of your theme.
October 3, 2008 @ 4:46 pm
Kiten
I mean is there any plugin for this?
October 3, 2008 @ 4:48 pm
Ian
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?
Thanks
October 5, 2008 @ 1:47 am
Ryan
@Kiten: None that I know of.
@Ian: You don’t need two different pages, you can just style things differently to fix inconsistencies between the browsers. Check out a post I’ve written on how to better handle redirection using conditional comments.
October 5, 2008 @ 8:56 am
yedmart.com/blog » Blog Archive » Internet Explorer redirect script
[...] to Dao by Design, yedmart.com now has a script that detects if the website is being accessed via Internet Explorer 6 [...]
October 21, 2008 @ 3:00 pm
GirlyBlogger » Blog Archive » Internet Explorer: Matando diseños CSS
[...] Firefox? La capacidad de arruinar un increíble diseño CSS, nada más. Como escribió Ryan en Dao by Design hace tiempo, es realmente doloroso crear un diseño en Firefox, que luego va a lucir desastroso en [...]
October 27, 2008 @ 10:05 am
mileq
thank you – you save my live
November 29, 2008 @ 9:59 pm
tk
Bah to ie! This was really helpful, thanks for releasing this great script!
December 31, 2008 @ 10:16 am
Matt
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!
January 11, 2009 @ 10:08 pm
haider_up32
is there any javascript which can detect ie users and warn them to download firefox
January 20, 2009 @ 8:03 pm
amenity
Ah, you’re a lifesaver. Thanks so much.
February 5, 2009 @ 5:01 am
Chris Lee
It’s work! Thank your great script!
February 12, 2009 @ 2:46 pm
Bazza
Man, this is bloody excellent! I love you! lol
March 20, 2009 @ 8:44 pm
Tom
Thank you so much for this, I spent ages trawling around the internet for this, and this is so simple – yet so great!
Anything to support the Bring Down IE6 campaign
>>http://www.facebook.com/home.php#/group.php?gid=51915907298
Thanks again
-Tom
March 22, 2009 @ 3:28 am
Jim N.
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.
July 16, 2009 @ 10:10 pm
Stone Deft
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
July 23, 2009 @ 12:49 am
Rakesh
Wow Ryan!! Thank you so much for the script. it works like charm. Great work! bye bye oldie!
July 23, 2009 @ 11:09 am
JQuest
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…=(
September 17, 2009 @ 10:18 am
JQuest
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…
HELP!!
September 17, 2009 @ 10:45 am
Ryan
@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.
September 17, 2009 @ 11:20 am
JQuest
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…
September 17, 2009 @ 11:51 am
Sebastijan
Thank you, it helps me go through css position problem in explorer browser.
October 6, 2009 @ 4:25 am
Martin Dvorak
Thanks for your script, one of my sites http://jivova.ic.cz 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.
December 18, 2009 @ 3:04 pm
Christopher Ryan
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.
February 19, 2010 @ 6:37 am
Jonesin'
THANK YOU THANK YOU THANK YOU!!!!!!!! I HATE Internet Explorer too. This is what i needed.
March 5, 2010 @ 9:28 am
Greg
Awesome, am going to use this heaps. United we stand against corporate oppression.
March 15, 2010 @ 3:26 pm
Malcom McCutcheon » Blog Archive » Just Say No to Microsoft Internet Explorer
[...] why I’ve drawn a line in the sand. I’ve set up a script that will automatically redirect visitors that use IE 6, 7, 8, 9 whatever…to this page every [...]
March 22, 2010 @ 8:26 pm