admin管理员组文章数量:1287598
when get a element's style, we always use
if(document.defaultView && document.defaultView.getComputedStyle)
to check whether the browser support the method or not.
why not use if(window.getComputedStyle)
?
when get a element's style, we always use
if(document.defaultView && document.defaultView.getComputedStyle)
to check whether the browser support the method or not.
why not use if(window.getComputedStyle)
?
-
See developer.mozilla/en/DOM/window.getComputedStyle for an explanation + exception (under
defaultView
) – Alex K. Commented Nov 15, 2011 at 12:53
2 Answers
Reset to default 8So in short, the reason why we use document.defaultView && document.defaultView.getComputedStyle
is that we want a cross-browser working-on-every-element method of checking whenever it supports fetching puted styles.
Simple if(window.getComputedStyle)
would fail for iframes in Firefox 3.6 (according to article linked in ment by Alex K.).
According to the MDN defaultView
is no longer required
In many code samples, getComputedStyle is used from the document.defaultView object. In nearly all cases, this is needless, as getComputedStyle exists on the window object as well. It's likely the defaultView pattern was a bination of folks not wanting to write a testing spec for window and making an API that was also usable in Java.
There was a bug in Firefox 3.6 (2010/2011) that needed defaultView
fix
本文标签:
版权声明:本文标题:javascript - what's the difference bewteen document.defaultView.getComputedStyle and window.getComputedStyle - Stack Ove 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741314196a2371822.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论