What’s the point of document.defaultView?

The OP asks the question, “What’s the point of document.defaultView“, and the answer really doesn’t have anything to do with getComputedStyle. The document.defaultView property is simply a way of obtaining the window object if one has a reference to the document object contained in that window. There are cases where the window object you are seeking to reference (or defaultView) is not in the same window scope as the code you are running.

One example of this is if you have a reference to the document object in an iframe, and wish to conveniently get a reference to the window object of that iframe.

Another case might be where you are running in privileged context in the browser scope (eg, chrome code in Firefox), and you happen to have a reference to the document object of a tabbrowser, or another window.

Or, as Dagg Nabbit points out, if in any of these cases you have a reference to an element within the window, you could access the parent window of that element through element.ownerDocument.defaultView

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)