I want to only allow users with IE8 (not IE6, IE7) or another browser to access my site when logged in.
I followed: http://code.google.com/p/ie6-upgrade-warning/ But
Using javascript you can ask which browser have sent the request>
<script type="text/javascript">
function detectBrowser()
{
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
if (browser=="Microsoft Internet Explorer")
&& (version>=8))
{
alert("Your browser is good enough!");
}
else
{
alert("It's time to upgrade your browser!");
}
}
</script>
Is this party over? ><
It is, but I think the information here can be updated a bit.
By today's standards, "today" being October 29 of 2013, you can use this meta tag to trigger the latest IE Browser and Document modes and trigger the installation of Google's Chrome Frame in older IEs:
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
This allows you to server specific IE6/7 styles. Keep in mind that I'm saying 'styles' not 'style sheets', meaning: You'd only use a single CSS file and in it are all your IE6 and IE7 styles. This is to minimize HTTP requests... but that's a totally different conversation.
Anyway, with the above snippet there's no need for scripts or Conditional Comments.
Note: Google Chrome Frame will be retired in January 2014 - more info here.
Personally I would recommend users to upgrade IE for security reasons. I would use a conditional comment to target browsers below IE8.
<!--[if lt IE 8]>You are using an outdated version of Internet Explorer. For security reasons you should upgrade your browser. Please go to Windows Updates and install the latest version.<![endif]-->
This message should be unobtrusive but graceful. You should also make the website usable for those that cannot upgrade their browsers.
Probably the best way would be to detect the user's browser User-Agent string and redirect them to a page asking them to upgrade (or download a different browser such as firefox or chrome) if they are using an old version of IE. You can see examples of the user agents of IE 7 and 8 on this IE developer blog entry. Older versions of IE follow a similar pattern.
One thing you should not do, however, is assume that any user agent string not following a certain pattern is invalid. Just check for MSIE ([0-9]) and see if it's in range; if it's missing entirely, assume the browser is supported. If it's MSIE 7, then further check for the Trident marker indicating compatiblity mode (and, I suppose, ask the user to turn it off). This will allow for other, future upstart browsers to have a fighting chance at rendering your page without turning them away at the door :)
Depends on how you've coded your (X)HTML, but IE8 should use standards mode (not IE7 mode) if you have a strict doctype like:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
at the top of your HTML files.
XHTML 1.0 Specs - Strictly Conforming Documents
Here's a good post about how different doctypes/etc affect IE8's rendering mode: Understanding Compatibility Modes in Internet Explorer 8
The very idea that you're "banning" IE 6 and 7 users from your website is ridiculous. A lot of people can't upgrade their browser or install another one because of work restrictions or because they don't know how. Barring these people from using your site will just cost you users in the long run.
Either fix your JavaScript, work around the problems or gracefully degrade so that the site will work well even if it's turned off.
EDIT: I posted some more information in a comment below which should really be in this post:
It's often possible to detect IE and work around it. Hell, you can even use conditional comments to load a different version of the JavaScript. Using a JS framework will abstract away the differences between browsers to a level you don't need to worry about. Or just grab IE7.js and stick that on the site - I hear it gets things working like you wouldn't believe.