Skip to content Skip to sidebar Skip to footer

What's The Difference Bewteen Document.defaultview.getcomputedstyle And 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

Solution 1:

So 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 computed styles.

Simple if(window.getComputedStyle) would fail for iframes in Firefox 3.6 (according to article linked in comment by Alex K.).

Post a Comment for "What's The Difference Bewteen Document.defaultview.getcomputedstyle And Window.getcomputedstyle"