0

I've been developing a web application, and I have noticed that in testing with IE, there are major issues with certain critical display elements. For this reason, I need to block off the web app from IE users and send them to another page to download either Firefox or Chrome.

I've been looking for a way to do this, but I can't find any easy guide that is only for IE. I've found and tried some snippets, but they won't work, as they are merely used to determine and print browser/OS/etc. information. I'd really appreciate your help!

  • 1
    Rather than preventing them from visiting the site entirely, wouldn't it seem friendlier to the user to just display a *warning* that it won't display correctly in their browser, but while still *allowing* them to try it if they really want to? And of course, if you're going to blacklist browsers, only block the ones you actually know are a problem (IE up to version X, but not all future versions of IE) – jalf Mar 27 '11 at 21:56
  • 1
    Are you _sure_ you want to do that? Do you know that all your prospective users / customers are willing or indeed _able_ to install another browser? IE still accounts for a substantial percentage of the installed browser base, which you may not like, but may have to put up with. – AAT Mar 27 '11 at 22:11
  • 1
    fix your application, don't expect other to change there browser's because you can't code. –  Mar 27 '11 at 22:35

5 Answers5

2

Instead of blocking it outright, consider an informative message. That's incidentally also where IE is somewhat useful for once:

<!--[if IE]><div class="info-bar">Your browser is not supported. Some
parts of this application might be non-functional.</div><![endif]-->
mario
  • 144,265
  • 20
  • 237
  • 291
  • 1
    Or, if the OP really needs to block everything, use this sort of code in the `` tag to serve up a CSS file that sets everything to `display: none;` *except* for a message. It'll stop everyone who doesn't know how to get around it, and those users are probably smart enough to use a browser which is supported in the first place (or use one when they see you message). – Blair McMillan Mar 27 '11 at 22:06
  • Thank you. I believe I'll consider this as an alternative...but this is very reliant on jQuery, which (as I'm sure you all know) is a pain with IE. – Jonathan Thornton Mar 28 '11 at 21:18
  • @Jonathan: The conditional comment trick does not depend on jQuery or Javascript. It's a built-in IE feature. – mario Mar 28 '11 at 21:21
1

One way is to check the user agent, and you can access this via $_SERVER['HTTP_USER_AGENT']

if(preg_match('/MSIE/i',$_SERVER['HTTP_USER_AGENT']))
    {
        // Internet Explorer!
        // header("Location: noie.php");
        // exit();
    }

However this isn't always reliable, so another way is to check to see if your features are available via javascript, such as:

if(window.localStorage){
  // you can use local storage
} else {
  // you can't
}

If this seems like a pain(and it is), I'd highly suggest checking out Modernizer to help your feature detection.

Mike Lewis
  • 63,433
  • 20
  • 141
  • 111
1

Browser sniffing on the server side is a bad idea because it is unreliable and not a proof that a given browser is unable to use your app.

First, certain browsers (like Opera) can/will send in another user agent because it makes the browser more 'compatible' (in other words, it works around the very technique you plan to use).

Second, it's not because it's Internet Explorer that it will necessarily not work. Your attempt will also rule out Internet Explorer 9, which has very good chances of being compatible with your web app.

Instead, you should, on the client-side, check that features you expect are indeed there. You rely on document.getElementsByClassName? Try this:

if (document.getElementByClassName == undefined)
    document.location.replace('Unsupported browser URL here');

You rely on <canvas>? Try this:

if (document.getElementById('canvas-element').getContext == undefined)
    document.location.replace('Unsupported browser URL here');

You rely on complex CSS3 rules? Have such a rule hide a message intended to legacy browsers.

.error-message:not(.unexistant-class) {
    /* this rule will be dropped by browsers that don't support the not()
        selector */
    display:none;
}

In short, check for features instead of for a user agent. If the client has all the features you want, there's no reason to leave it behind.

zneak
  • 134,922
  • 42
  • 253
  • 328
0

You have to check the user agent header :

http://php.net/manual/en/function.get-browser.php

Spyros
  • 46,820
  • 25
  • 86
  • 129
0

Well you could also use this code http://www.ie6nomore.com/

Jason
  • 15,064
  • 15
  • 65
  • 105