使用 jQuery 1.3+ 检测 IE8、IE7、Safari、FireFox?

发布于 2024-07-23 05:27:47 字数 302 浏览 5 评论 0原文

我需要根据每个浏览器更改一个值,因为它们的呈现方式都不同。

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 技术交流群。

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

发布评论

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

评论(5

一绘本一梦想 2024-07-30 05:27:47

如果您必须进行浏览器检测(尽管有针对它的警告),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).

神也荒唐 2024-07-30 05:27:47

您是否或考虑过使用 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.

糖果控 2024-07-30 05:27:47

他们的渲染有何不同? 有没有办法使用功能检测而不是浏览器嗅探? 当新的浏览器出现时,它不太容易损坏,并且对边缘的容忍度更高。

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.

街道布景 2024-07-30 05:27:47

您可以使用 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 the jQuery.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.

水水月牙 2024-07-30 05:27:47

它们都以不同的方式呈现工具提示的顶部 css 值。

var container = $('<div id="personPopupContainer">'
    + '<div id="personPopupContent">'
    + '</div>'
    + '</div>');

var pos = $(this).offset();
var width = $(this).width();
var reposition = { left: (pos.left - width) + 'px', top: pos.top + msg + 'px' };

container.css({
                    top: reposition.top
             });

They all renders the tooltip's top css value differently.

var container = $('<div id="personPopupContainer">'
    + '<div id="personPopupContent">'
    + '</div>'
    + '</div>');

var pos = $(this).offset();
var width = $(this).width();
var reposition = { left: (pos.left - width) + 'px', top: pos.top + msg + 'px' };

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