I can get window.document but how can I get document.window? I need to know how to do it in all browsers.
A:
If you're going to be doing cross-browser Javascript, you should really look into one of the stable, well supported libraries. jQuery is my personal favorite.
This is just the first of many such questions you'll run into if you decide to "roll your own".
DarkSquid
2009-08-27 00:08:11
And how, pray tell, do you get the `window` object from the `document` object in jQuery?
Crescent Fresh
2009-08-27 00:24:10
+2
A:
The Window object is the top level object in the JavaScript hierarchy, so just refer to it as window
Kevin Hakanson
2009-08-27 00:25:09
+1
A:
You can go with document.defaultView if you want to exclude Microsoft browsers.
kennebec
2009-08-27 01:50:48
Yes. Just remember that as per specs, `document.defaultView` does not have to be the same object as `window` (and, it is in fact different in some older clients, e.g.: Safari 2.x)
kangax
2009-08-27 02:40:35
A:
Well, this is the solution I went with. It works, but I hate it.
getScope : function(element) {
var iframes = top.$$('iframe');
var iframe = iframes.find(function(element, i) {
return top[i.id] ? top[i.id].document == element.ownerDocument : false;
}.bind(this, element));
return iframe ? top[iframe.id] : top;
}
Joren
2009-08-28 17:44:01
What's IE only about it? Seems to work fine in FF\Saf\IE\Chrome.It's not necessary in anything but IE however, since the other browsers all extend the elements automatically in the right scope.
Joren
2009-08-31 23:15:10