开发者

How can I determine whether a user is on IE...and send them to a page saying my web app isn't supported on IE?

开发者 https://www.devze.com 2023-02-19 22:48 出处:网络
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 fro

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 th开发者_如何学Cey won't work, as they are merely used to determine and print browser/OS/etc. information. I'd really appreciate your help!


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]-->


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.


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.


You have to check the user agent header :

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号