Ticket #10373 (closed enhancement: fixed)
`document.defaultView` => `window`
| Reported by: | paul.irish | Owned by: | rwaldron |
|---|---|---|---|
| Priority: | low | Milestone: | 1.8 |
| Component: | css | Version: | git |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
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);
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
comment:1 Changed 20 months ago by rwaldron
- Owner set to rwaldron
- Priority changed from undecided to low
- Status changed from new to assigned
- Component changed from unfiled to css
- Milestone changed from None to 1.next
comment:3 Changed 13 months ago by mikesherov
- Milestone changed from 1.next to 1.8
can you please resubmit this now that FF3.6 is gone?
comment:4 Changed 12 months 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 11 months ago by Rick Waldron
- Status changed from assigned to closed
- Resolution set to fixed
Update document.defaultView.getComputedStyle. Fixes #10373
Changeset: f7ee1f6e59f0b465f5f64bf6ac52108e445efaac
comment:6 Changed 7 months 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?
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
