Bug Tracker

Opened 6 years ago

Closed 5 years ago

Last modified 4 years ago

#10373 closed enhancement (fixed)

`document.defaultView` => `window`

Reported by: paul.irish Owned by: Rick Waldron
Priority: low Milestone: 1.8
Component: css Version: git
Keywords: Cc:
Blocked by: Blocking:


grabbing getComputedStyle off of defaultView has been commonplace for many years, but its unnecessary.

the same function has worked off the global window object all the way back, AFAICT.

I posted about this on g+ ...

oftentimes you see document.defaultView.getComputedStyle used instead of the getComputedStyle that's on the window object. I imagine that's because the spec'd "interface" that getComputedStyle was defined for defaultView before it was decided that the global object inherited the defaultView interface. http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-OverrideAndComputed

Regardless, we now have a lot of code with this defaultView action, but I feel like its unnecessary. Funnily enough, check out this confused code example from PPK:

else if (window.getComputedStyle)
var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);

~via http://www.quirksmode.org/dom/getstyles.html

Does anyone know the last browser that had gCS available on d.dV but not on window?

and david baron responded...

I don't think there were any. I'd guess the whole defaultView business was some combination of (1) not wanting to write a spec for window and (2) making an API that was also usable in Java.

grabbing the more convenient gCS will kill off a lot of bytes and some extra conditional complexity.

Change History (8)

comment:1 Changed 6 years ago by Rick Waldron

Component: unfiledcss
Milestone: None1.next
Owner: set to Rick Waldron
Priority: undecidedlow
Status: newassigned

comment:3 Changed 5 years ago by mikesherov

Milestone: 1.next1.8

can you please resubmit this now that FF3.6 is gone?

comment:4 Changed 5 years ago by dmethvin

In at least a few places, it seems we're doing this because the element we're interrogating may be in another frame. So it's not the global window object. There isn't a lot to be gained in any case, since there are very few uses at this point. I would be happy with this just being closed if there isn't a compelling reason to make changes.

comment:5 Changed 5 years ago by Rick Waldron

Resolution: fixed
Status: assignedclosed

Update document.defaultView.getComputedStyle. Fixes #10373

Changeset: f7ee1f6e59f0b465f5f64bf6ac52108e445efaac

comment:6 Changed 4 years ago by brian.moschel@…

This breaks for a test framework I work on: FuncUnit. FuncUnit opens a popup window with the application under test, and the parent window runs commands in that window. In IE, window.getComputedStyle(elem) breaks, because window is the opener window, but elem is in the popup window. elem.ownerDocument.defaultView.getComputedStyle(elem) works fine, because it gets the relevant document. Can the window part of this commit be reverted for this reason?

comment:7 Changed 4 years ago by dmethvin

@brian, can you create a new ticket for this? It seems like it would be reasonable. A simple test case would help as well.

comment:8 in reply to:  7 Changed 4 years ago by anonymous

Replying to dmethvin:

@brian, can you create a new ticket for this? It seems like it would be reasonable. A simple test case would help as well.

I've just created a ticket which I believe describes this behaviour - http://bugs.jquery.com/ticket/14150

Note: See TracTickets for help on using tickets.