Block the Internet Explorer 6 and other old browsers with a small Warning-div
Hi there,
in the last days we relaunched our website (www.team-noir.net). We used the CSS Framework YAML and create a small website (6 pages). But i spent 4 hours just for bugfixing the fxxxx Internet Explorer 6.0 and 5.5
They don’t know variables heights or transparent png’s … certainly you know this!
I was so angry about loosing this time for old, silly and unsecure browers …
So we decided to implement a small but important WARNING to all users with old browsers. I found a very nice script on think2loud.com
I just extended the browser-detection, you will find the hole skript >>here<<:
function badBrowser(){
if($.browser.msie && parseInt($.browser.version) <= 6){ return true;}
if($.browser.opera && parseInt($.browser.version) <= 9) { return true;}
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
var ffversion=new Number(RegExp.$1)
if (ffversion<=2) { return true;}}
if ($.browser.safari && (navigator.appVersion.indexOf("1") != -1) ){return true;}
if ($.browser.safari && (navigator.appVersion.indexOf("2") != -1) ){return true;}
if ($.browser.safari && (navigator.appVersion.indexOf("3") != -1) ){return true;}
return false;
}
There are a few ways to detect the browser and correct version. Most problems i had with Safari – because i cant’t find any stand-alone Version-Code – so i had to workaround … and built 3 queries.
If you have an better an easier idea – please let me know!
You can check our Sites now with “old” Browsers (IE <=6, Opera <9, Safari <=3, Firefox <=2) and see what happens …
… Martin
UPDATE (25.06.2009):
I have a new version for browser detecting. Now the “Opera Problem” is solved, every Opera <= Version 9.5 gets now the Warning-Popup, and not all 9.x versions.
(Thanks to Ulf
)
function badBrowser(){
if($.browser.msie && parseInt($.browser.version) <= 6){ return true;} //IE ab ver. 6.0
if($.browser.opera && ($.browser.version *10) <= 95) { return true;} //Opera ab ver. 9.5
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
var ffversion=new Number(RegExp.$1)
if (ffversion<=2) { return true;}} //Firefox ab ver. 2.0
if ($.browser.safari && (navigator.appVersion.indexOf("1.") != -1) ){return true;} //Safari ver. 1.0
if ($.browser.safari && (navigator.appVersion.indexOf("2.") != -1) ){return true;} //Safari ver. 2.0
if ($.browser.safari && (navigator.appVersion.indexOf("3.") != -1) ){return true;} //Safari ver. 3.0
return false;
}
more problems? tell us …
UPDATE (26.07.2009):
new badBrowser Version released !!!
Related posts:





I think there is a problem with some browsers and there identification. The sent identification from the browser can be modified by the user. Maybe the program TuneUp Utilities change the browser identification from Internet Explorer.
I think this is a problem when identifies the browser.
And also browsershots shows that the Javascript information is shown with version 9.0.0.5.
So this is still a great idea to inform people about old browser versions, but it is also not working in every case like expected. There must be done some fine-tuning i think. But this is still better as working hours and days on optimization for outdated browsers because some people are to lazy to update there system!
I think I have identified one problem. There is called “parseInt()” which makes a integer value (from a double or float value). If the browser is Opera 9.64 the parseInt() function makes: parseInt(9.64) = 9. Because the decimal places will cut off. So the if becomes: parseInt(9) < = 9 which is true!
We will work on!
Man darf nicht vergessen, dass die meisten Leute nicht böswillig auf den alten Browserversionen sitzen bleiben, sondern meist einfach nicht genug rechte am PC besitzen um den Update durchzuführen..
@michael
i dont think that’s the main problem.
and of course our small warning advice can help those people to speak with their admin and tell him the problem!
I put the code as mentioned in the head of the main page and the rest of the files in a script map Scripts/badBrowser which has been put in the root.
I have IE 8 and when I open the main page of my site locally I get the warning, when I go to my site on internet I not get a warning.
When I change the code for FireFox from Version 2 into Version 4 ( I have actually Version 3) then I get the warning aswell opened locally as on internet and the warning disapears again when I change the code into Version 2 as it supposed to be.
So the whole thing works for Firefox, but for IE. Who can help me, please.
Thanks in advance.
Richard
@richard
hi, thanks for your comment.
please check our website (http://www.team-noir.net) with your browsers.
because our tests passed well in IE8-6, FF2-3.5.
we cant’t found any difference between testing local or online.
# maybe you forgot a comma, bracket or something else ?
# empty your browsercache ?
# test your website with http://browsershots.org
i dont have a explanation for your local/web conflict, sorry.
keep us up do date!
greetz
martin
I like you’re approach, so I had a look at the script and found some errors. Additionally I minified the whole script so it’s faster.
Here we go:
function badBrowser(){if($.browser.msie && parseInt($.browser.version,10)<=6){return true;}if($.browser.opera&&($.browser.version*10)<=95){return true;}if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){var ffversion=Number(RegExp.$1);if(ffversion0){c_start=document.cookie.indexOf(c_name+"=");if(c_start!=-1){c_start=c_start+c_name.length+1;c_end=document.cookie.indexOf(";",c_start);if(c_end==-1){c_end=document.cookie.length;}return unescape(document.cookie.substring(c_start,c_end));}}return "";}function setBadBrowser(c_name,value,expiredays){var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);document.cookie=c_name+"="+escape(value)+((expiredays===null)?"":";expires="+exdate.toGMTString());}if(badBrowser()&&getBadBrowser('browserWarning')!='seen'){$(function(){$('You are using an unsupported browser. Please switch to FireFox, Opera, Safari or Internet Explorer 7. Thanks! [close]').css({backgroundColor:'#fcfdde','width':'100%','border-top':'solid 1px #000','border-bottom':'solid 1px #000','text-align':'center',padding:'5px 0'}).prependTo("body");$('#warningClose').click(function(){setBadBrowser('browserWarning','seen');$('#browserWarning').slideUp('slow');return false;});});}
Okay, with the code that’s not working correctly. I uploaded the file at Rapidshare, the normal one and the minified one.
http://rapidshare.com/files/255900524/badbrowser.7z
@fleshgrinder
thanks for your work. in the next days i will have a look at your code.
you wrote: “with the code that’s not working correctly” ?
wich code do you mean? mine or yours?
No, no, I didn’t ment the script, I was writing about my own post before. I wanted to use the <code> Tag to just post the altered script, but the included HTML was transformed by the Blog engine. All scripts are working, I just made some simple changes (now it will go smoothly through the JSlint check) and minimised it.
This is pretty cool. I will defiantly use this in my next site.
For me I still try to make Ie 6 half decent but I am not going to spend tons of time of trying to make it super nice for a dieing browser so this warning is perfect.
I like the minified version that Fleshgrinder made since it is smaller but it’s hard to update.
Like when I load it in VS2008 it just one huge ass line and that I got to scroll through to make changes.
So I think it is better to just have some like variables at top for all the stuff a user might change like the message.
This is what I have so far but I don’t know how to put like the CSS stuff in a variable and how what should I should be putting from Safari in a variable.
Like I made one for opera and firefox since when I make sites I test against the latest versions only. I don’t go back and test older versions so to change the script to the newest version is a good feature in my eyes.
Plus why not detection for chrome? I know it is new and stuff but they will eventually have newer versions and like I said I test again only new versions of the browsers.
// More info @http://blog.team-noir.net/2009/06/fight-old-browsers-warning-with-jquery/
var msg = ‘You are using an older browser that this site has not been fully tested in. You may not experience the site as intended. Please switch or upgrade to the latest version of FireFox, Opera, Safari or Internet Explorer 8. Thanks! [close]‘;
var IeVersion = 6;
var OperaVersion = 95;
var firefoxVersion = 3.5;
function badBrowser() { if ($.browser.msie && parseInt($.browser.version, 10) <= IeVersion) { return true; } if ($.browser.opera && ($.browser.version * 10) <= OperaVersion) { return true; } if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { var ffversion = Number(RegExp.$1); if (ffversion 0) { c_start = document.cookie.indexOf(c_name + “=”); if (c_start != -1) { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexOf(“;”, c_start); if (c_end == -1) { c_end = document.cookie.length; } return unescape(document.cookie.substring(c_start, c_end)); } } return “”; } function setBadBrowser(c_name, value, expiredays) { var exdate = new Date(); exdate.setDate(exdate.getDate() + expiredays); document.cookie = c_name + “=” + escape(value) + ((expiredays === null) ? “” : “;expires=” + exdate.toGMTString()); } if (badBrowser() && getBadBrowser(‘browserWarning’) != ’seen’) { $(function() { $(msg).css({ backgroundColor: ‘#fcfdde’, ‘width’: ‘100%’, ‘border-top’: ’solid 1px #000′, ‘border-bottom’: ’solid 1px #000′, ‘text-align’: ‘center’, padding: ‘5px 0′ }).prependTo(“body”); $(‘#warningClose’).click(function() { setBadBrowser(‘browserWarning’, ’seen’); $(‘#browserWarning’).slideUp(’slow’); return false; }); }); }
I just tried it in chrome and I get the browser supported message. What kinda sucks. Is this meant to happen or did I change something that messed it up?
@chobo2
thanks for your post and the optimization.
you are right – i have not testet with google chrome yet.
chrome sends a similar “user-agent” as safari do -> so our script alerts.
Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13
in the next days i will fix it and transfer your code to our script.
see you! martin
Cool. I look forward for the new version.
I been reading too that kinda concerns me is that now in Jquery 1.3 they now recommend to use “Support” instead of browser detection. Even though they have no plans to kill browser detection off any time soon it still kind of concerns me.
I read all the people who been praising this “Support” that seems to be like feature detection.
I don’t know why people are so against browser detection. I can see that feature detection can be useful but for me I am just looking to have a little friendly reminder that tells the user “upgrade to a better version then IE6 and that this site was tested on these Versions of other Firefox(ex 3.5) and if your not using these versions or higher you might not see the site as intended”.
I know they also talk about browser detection not detecting obscure browsers but to that I say who cares. I don’t want to be always be programing for the lowest common denominator(better optimize for IE 5.5 one person in the world might still use it). If they choose to use some browser no one has heard of then well that’s their choice but should not come running to anyone whining if something does not work.
So what are your thoughts? I see this post was started June 19th. So Jquery already announced that they no long recommend browser detection.
i will test and publish the chrome case on weekend.
i read about jquery and browser detection, but i dont care …
i think there will and must also be a way to detect the executing version. in our case we use basic javascript for detecting – surely enough for the moment.
the topical from the last days (fight-old-browsers-youtube-follows/) show us the right way – destroy old browser assistance
greetz
@blumentritt
Cool can’t wait to see the new chrome test case.
For other browsers like chrome and firefox I think it will be very rare that people will stick with older version for long since if they probably know about updating. It is really just the IE crowd.
Ya I think the right way is stop supporting older browsers but I don’t believe the small sites have the power. Like most of us are just happy anyone is coming to our sites so you don’t want to destroy the little user base we have.
Thats why it good that Youtube and digg are doing it. They have the power to influence people to change.