My First Approved Script on CodeCanyon.net
Jan, 2010
29

How to detect and avoid browsers with Javascript

I am going to go ahead a regurgitate what everyone has been saying for years now, that IE6 is just well past its prime and its time to retire it. This has been beaten death time and time again, so I am not going to list all the reasons why we should drop it, I am just going to tell you how to make sure that users with IE6 are properly handled on your site.

Its actually very simple. First you drop in this bit of Javascript.

//Nothing special here... just telling javascript to kick IE users out
var browser=navigator.appName;
if(browser == "Microsoft Internet Explorer"){
window.location = "no_ie.html";
}else{
//you can remove this, I just like to see what browser we ARE seeing
//alert(browser);
}

This should stop IE users, if you are trying to detect some other browser or you are curious what the navigator.appName is returning just un comment the alert above. You can also change the window.location to be any URL you like. In my case I redirect them to a page that thoroughly insults IE6.

Add this to your sites and support IEDeathMarch.org

Post to Twitter Tweet This!

This entry was posted on 01.29.2010 at 6:11 pm and is filed under Code Bin. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Comments

1 Response to “How to detect and avoid browsers with Javascript”

01.29.2010 | 7:32 pm

I am not a fan of targeting websites with javascript and telling them they are not allowed to view the content they came to my websites for. I’d much rather use Andy Clarke’s Universal IE6 CSS sheet (http://forabeautifulweb.com/blog/about/universal_internet_explorer_6_css/) because I feel that it keeps the spirit of allowing unfortunate people who can’t upgrade their IE (Corperate world) still access the content even though they are not getting the full experience.

Besides that this was a pretty entertaining idea. =)

Leave a Reply

Green Web Hosting! This site hosted by DreamHost.