使用 jQuery 1.3+ 检测 IE8、IE7、Safari、FireFox?
我需要根据每个浏览器更改一个值,因为它们的呈现方式都不同。
if (navigator.appName == 'Netscape'){
top = 17;
}
这是有效的,但不幸的是 Firefox 和 Safari 都显示为“Netscape”
我如何使用 jQuery 1.3.2 来检测所有这些? 既然 jquery.browser
消失了,我在 jquery.support
下找不到任何信息。
谢谢!
I need to change a value based on each browser since they all render differently.
if (navigator.appName == 'Netscape'){
top = 17;
}
This was working but unfortunately both Firefox and Safari show up as "Netscape"
How would I use jQuery 1.3.2 to detect all these? I couldn't find any info under jquery.support
now that jquery.browser
is gone.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您必须进行浏览器检测(尽管有针对它的警告),ppk 的例程 是最新的(甚至通过 Chrome 和 iPhone)。
If you must have browser detection (despite the warnings against it), ppk's routine is current (even up through Chrome and iPhone).
您是否或考虑过使用
reset.css
样式表 将所有浏览器的默认值设置为零? 如果没有,我建议您这样做,因为它可能会解决您当前的问题以及未来潜在的问题。它可能会有所帮助,因为它将所有浏览器设置为基线零,因此当您应用填充或定位时,它应该在所有浏览器中具有相同的效果。
Are you, or have you considered, using a
reset.css
stylesheet to set all browsers' defaults to zero? If not I recommend you do so since it might solve your current problem, as well as potential future ones.It may help because it would set all browsers to a baseline zero, so when you apply padding or positioning, it should have the same effect in all browsers.
他们的渲染有何不同? 有没有办法使用功能检测而不是浏览器嗅探? 当新的浏览器出现时,它不太容易损坏,并且对边缘的容忍度更高。
What are they rendering differently? Is there a way you can use capability detection rather than browser sniffing? It's less prone to breakage when new browsers come along, and more tolerant of the fringe.
您可以使用
jQuery.browser
对象。 它在 jQ 1.3 中已弃用,取而代之的是jQuery.support
,但目前还没有立即完全删除它的计划,所以你应该是安全的。也就是说,使用浏览器嗅探虽然非常简单且诱人,但通常并不是最好的方法。 由于听起来您在某些浏览器以不同方式执行 CSS 时遇到了问题,因此您可能需要查看
jQuery.support.boxModel
。you can use the
jQuery.browser
object. It's deprecated in jQ 1.3 in favour of thejQuery.support
, but there's no immediate plans to remove it altogether, so you should be safe.That said, using browser sniffing, while very easy and tempting, isn't usually the best way to do things. Since it sounds like you're having problems with some browsers doing CSS differently, you might want to look at
jQuery.support.boxModel
.它们都以不同的方式呈现工具提示的顶部 css 值。
They all renders the tooltip's top css value differently.