如何确定用户是否使用 IE...并将他们发送到一个页面,说明 IE 不支持我的网络应用程序?
我一直在开发一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不要直接阻止它,而是考虑一条信息丰富的消息。顺便说一句,这也是 IE 暂时有用的地方:
Instead of blocking it outright, consider an informative message. That's incidentally also where IE is somewhat useful for once:
一种方法是检查用户代理,您可以通过
$_SERVER['HTTP_USER_AGENT']
访问它,但这并不总是可靠,因此另一种方法是检查您的功能是否可用通过 javascript,例如:
如果这看起来很痛苦(确实如此),我强烈建议查看 Modernizer 帮助您进行特征检测。
One way is to check the user agent, and you can access this via
$_SERVER['HTTP_USER_AGENT']
However this isn't always reliable, so another way is to check to see if your features are available via javascript, such as:
If this seems like a pain(and it is), I'd highly suggest checking out Modernizer to help your feature detection.
在服务器端进行浏览器嗅探是一个坏主意,因为它不可靠,并且不能证明给定的浏览器无法使用您的应用程序。
首先,某些浏览器(如 Opera)可以/将发送另一个用户代理,因为它使浏览器更加“兼容”(换句话说,它围绕您计划使用的技术工作)。
其次,并不是因为它是 Internet Explorer,它就一定不能工作。您的尝试还将排除 Internet Explorer 9,因为它很有可能与您的 Web 应用程序兼容。
相反,您应该在客户端检查您期望的功能是否确实存在。您依赖
document.getElementsByClassName
吗?试试这个:您依赖
吗?试试这个:
您依赖复杂的 CSS3 规则吗?让这样的规则隐藏针对旧版浏览器的消息。
简而言之,检查功能而不是用户代理。如果客户拥有您想要的所有功能,就没有理由放弃它。
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:You rely on
<canvas>
? Try this:You rely on complex CSS3 rules? Have such a rule hide a message intended to legacy browsers.
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.
您必须检查用户代理标头:
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
那么您也可以使用此代码 http://www.ie6nomore.com/
Well you could also use this code http://www.ie6nomore.com/