如何检测 Safari 3.0.x 中的怪异模式?
Safari 3.0.x 不支持 document.compatMode 属性来检测文档是以标准模式还是以怪异模式呈现。 Safari 3.1 及更高版本确实支持它。如果 document.compatMode 不可用,如何检测 Safari 3.0.x 中的文档模式?
Safari 3.0.x doesn't support the document.compatMode property to detect whether the document is rendered in standards or in quirks mode. Safari 3.1 and newer do support it. How do I detect the document mode in Safari 3.0.x if document.compatMode is not available?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
快速 Google 搜索会产生:"如何确定文档的兼容模式"
基本上,您创建了一个具有无效 css 样式的
div
这只适用于怪异模式。然后检查新div
的样式以查看 CSS 是否被接受。如果被接受,则文档处于怪异模式。解释代码 :
我会为你测试一下,但我无法运行 Safari。如果可以的话请测试一下并在评论中报告结果。
A quick Google search results in: "HOWTO determine the document's compatibility mode"
Basically you create a
div
with an invalid css style that would only work in quirks mode. You then check the newdiv
's style to see if the css was accepted. If it was accepted, the document is in quirks mode.To paraphrase the code:
I would test this for you but I can't run Safari. Please test it if you can and report the results in a comment.
大多数较新的浏览器都有
compatMode
,但某些较旧的浏览器没有。此类浏览器包括 Mac IE 和较旧的 WebKit,例如台式机和许多诺基亚手机上的 Safari 2。如果
document.compatMode
存在,则检查该值是否不是“BackCompat”
。如果是这种情况,则文档处于标准模式。这为 IE 带来了早期结果。否则,就没有
document.compatMode
,因此它是一个较旧的浏览器,可能支持标准模式渲染,但只是没有compatMode
属性。如果将元素的
width
设置为数值,则文档不处于标准模式。如果您觉得
if - else
更具可读性,则可以使用它;或者,也可以使用三元赋值。这解决了世界各国移动设备(例如诺基亚)中可能存在的较旧的 Webkit 版本。
在IE5.5及以下版本中会返回true。在任何具有损坏的 createElement 的浏览器上,
createElement
的存在推断检查都会失败(我相信是 Opera 5)。避免使用此函数进行一般性推论;始终尝试尽可能具体。
Most newer browsers have a
compatMode
but some older browsers don't. Such browsers include Mac IE and older WebKits, such as Safari 2 on desktop and many Nokia phones.If
document.compatMode
exists, then check that the value is not"BackCompat"
. If that is the case, the document is in Standards mode. This gets an early result for IE.Otherwise, there's no
document.compatMode
and so it is an older browser that might support standards mode rendering, but just doesn't have acompatMode
property.If setting an element to have a number value for
width
sets its width, the document is not in standards mode.You can use
if - else
if you find it more readable; or, alternatively, use a ternary assignment.This addresses older Webkit versions which may exist in mobile devices such as Nokias in countries around the world.
It will return true in IE5.5 and below. Existence inference check for
createElement
will fail on any browser that has createElement that is broken (Opera 5, I believe).Avoid using this function to make general inferences; always try to be as specific as possible.