views:

3094

answers:

9

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 I also wanted it to not allow IE7 users to use the main site when logged in (they can view public pages.) The reason is that the main web application has a lot of JavaScript effects that will only work 100% in IE8 rendering mode (or any other browser aside from IE.)

The problem with modifying the ie6 upgrade warning to be ie7 is that it looked like IE8 displayed my webpage in an IE7 rendering mode and "lies" about being ie7 and triggers the IE7 stylesheet code.

So how can I force IE8 to always render my page in IE8 mode?

+1  A: 

You can use CSS Conditional Comments

<!--[if IE 8]>
Special instructions for IE 6 here
<![endif]-->
AdamSane
And do what, use CSS to hide all the elements on the page? CSS can't restrict access.
Chad Birch
@AdamSane - These are just conditional comments - no need for the 'CSS' bit.@Chad - It shouldn't need to restrict access - just make a warning visible and hide anything that could confuse the user. If the user can break something by not having JavaScript working/working correctly, then there's a problem with the application.
Tom
+1  A: 

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"&gt;

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

Chad Birch
Not exactly. Anyone can trigger IE8's compatibility mode at anytime by clicking on the stupid broken page icon.
Chris Lively
+5  A: 

Correction to AdamSane's example:

<!--[if lt IE 8]> Special instructions for IE 7 or less here <![endif]-->

Scott
This won't work if the page is in Compatibility View mode. In that mode, IE8 uses the IE7 version info for conditional comments.
EricLaw -MSFT-
A: 

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.

Samir Talwar
It's hard to fix your JavaScript when you have to either neuter features or standards compliancy--IE loves to have its own interpretation of standard code, which often leaves you supporting IE or the rest.
STW
Also, I'm pretty sure he's not barring them from the site, but telling them that if they're using IE6/7 they may as well not even try. Warning your users that their incompatible client is not supported is good defensive coding.
STW
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 (http://code.google.com/p/ie7-js/) and stick that on the site - I hear it gets things working like you wouldn't believe.
Samir Talwar
I agree with the idea of "banning" IE 6 and 7 users. Of course I go a little further on one of our admin sites. We ban any non-current release browser version. Which means anything less then IE8, Firefox 3.6, Safari 4.0.4, etc. This is for security and performance reasons. Thus far our clients haven't balked.
Chris Lively
A: 

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>
Luixv
This won't work if the page is in Compatibility View mode. In that mode, IE8 uses the IE7 version info for conditional comments and the JavaScript user-agent.
EricLaw -MSFT-
+1  A: 

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 :)

bdonlan
+7  A: 

Use this tag:

<meta http-equiv="X-UA-Compatible" content="IE=8" />
Daniel
Yes, that will correctly force IE8 to render his site in IE8 mode, and cause JavaScript and Conditional Comments to report IE8. On the server side, checking for "Trident 4.0" in the user-agent header is also valid.Often we suggest that folks use "IE=EmulateIE8" just to ensure that any Quirks mode pages aren't inadvertently forced into Standards mode, but this poster seems like a standards-junkie and isn't likely to be using Quirks Mode pages.
EricLaw -MSFT-
+1  A: 

As has been mentioned I'd suggest the best way to achieve this is to use conditional comments to include a stylesheet specific to all versions of IE earlier than 8:

<!--[if lt IE 8]> Include CSS here <![endif]-->

The included CSS could set a warning to be visible or perhaps enable an overlay on the page which 'locks' users out. It might be a good idea to include some rules which hide important elements on the page which could otherwise confuse the user if they do not work as intended.

Your other option is to redirect the user to another page - I'm not a huge fan of redirects but if used with care they can be a suitable solution.

Have you considered why you're locking a large amount of users out of your site? Maybe you should take the time to work out how to either gracefully degrade your JavaScript, or the other way around; 'progressively enhance' with JavaScript.

On the other hand, you might have control over the systems used by the organisation using your site in which case you're probably OK locking people out for using non-standard systems.

Tom
A: 

This is really a simple answer for everyone out there.

First of all....read the documentation for browser usage on w3schools.com. 2nd check your own most visited site for browser usage.

w3schools lists their OWN usage. Because it's being used by people who live on the cutting edge, it's more likely to be viewed by people who use upgraded browsers.

Really people, look at the documentation.