jquery 1.4 的特征检测
我如何通过使用功能检测来检测浏览器是否是 firefox、ie(但不是 ie6)、opera、chrome 或 safari?
How would I go about doing a detect to see if the browser is either firefox, ie (but not ie6), opera, chrome or safari by using feature detection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
功能检测不应告诉您用户正在使用哪种浏览器。它的目的是告诉您浏览器是否可以处理您需要做的事情。
例如,如果您需要支持 ActiveX,您可能会检查
这比检查浏览器是否是 IE 更好,因为其他一些浏览器(当前或未来)也可能支持 ActiveX。
一个更有用的示例可能是遍历节点列表时的文本节点检查。
Feature detection is not supposed to tell you which browser the user is using. It is meant to tell you if the browser can handle what you need to do.
So for instance, if you need to support ActiveX, you might check
This is better than checking if the browser is IE because some other browser (current or future) might support ActiveX too.
A more useful example may be text node checking when traversing a node list.
对于 Safari:我将采用服务器端路线,即使用 Chris Schuld 的 Browser.php;除了 http 用户代理之外,关于 Safari 功能检测的文档很少。
For Safari: I'm going the server side route, ie using Chris Schuld's Browser.php; apart from the http user agent there's very little documentation about Safari feature detection.
我正在寻找答案,想也许有人已经解决了我的问题。
像许多人一样,我最终编写了自己的:
当然,您会想要自定义您的实现。我的例子只是展示了基本逻辑。
哈!
I was searching for an answer, thinking perhaps someone had solved my issue.
Like many, I ended up writing my own:
You will, of course, want to customize your implementation. My example just shows the base logic.
HTH!