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…:
Otherwise, lets put this together step by step.
Building the Script
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))
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:
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.