如何确定用户是否使用 IE...并将他们发送到一个页面,说明 IE 不支持我的网络应用程序?

发布于 2024-10-27 06:22:42 字数 219 浏览 2 评论 0原文

我一直在开发一个 Web 应用程序,我注意到在使用 IE 进行测试时,某些关键显示元素存在重大问题。因此,我需要阻止 IE 用户使用 Web 应用程序,并将他们发送到另一个页面来下载 Firefox 或 Chrome。

我一直在寻找一种方法来做到这一点,但我找不到任何仅适用于 IE 的简单指南。我找到并尝试了一些片段,但它们不起作用,因为它们仅用于确定和打印浏览器/操作系统/等。信息。我非常感谢你的帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

聽兲甴掵 2024-11-03 06:22:42

不要直接阻止它,而是考虑一条信息丰富的消息。顺便说一句,这也是 IE 暂时有用的地方:

<!--[if IE]><div class="info-bar">Your browser is not supported. Some
parts of this application might be non-functional.</div><![endif]-->

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]-->
故事未完 2024-11-03 06:22:42

一种方法是检查用户代理,您可以通过 $_SERVER['HTTP_USER_AGENT'] 访问它,

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

但这并不总是可靠,因此另一种方法是检查您的功能是否可用通过 javascript,例如:

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

如果这看起来很痛苦(确实如此),我强烈建议查看 Modernizer 帮助您进行特征检测。

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.

心头的小情儿 2024-11-03 06:22:42

在服务器端进行浏览器嗅探是一个坏主意,因为它不可靠,并且不能证明给定的浏览器无法使用您的应用程序。

首先,某些浏览器(如 Opera)可以/将发送另一个用户代理,因为它使浏览器更加“兼容”(换句话说,它围绕您计划使用的技术工作)。

其次,并不是因为它是 Internet Explorer,它就一定不能工作。您的尝试还将排除 Internet Explorer 9,因为它很有可能与您的 Web 应用程序兼容。

相反,您应该在客户端检查您期望的功能是否确实存在。您依赖 document.getElementsByClassName 吗?试试这个:

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

您依赖 吗?试试这个:

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

您依赖复杂的 CSS3 规则吗?让这样的规则隐藏针对旧版浏览器的消息。

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

简而言之,检查功能而不是用户代理。如果客户拥有您想要的所有功能,就没有理由放弃它。

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.

夜无邪 2024-11-03 06:22:42

您必须检查用户代理标头:

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

You have to check the user agent header :

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

梦里泪两行 2024-11-03 06:22:42

那么您也可以使用此代码 http://www.ie6nomore.com/

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文