views:

224

answers:

5

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
And how, pray tell, do you get the `window` object from the `document` object in jQuery?
Crescent Fresh
A: 

The document object does not have a window.

http://www.w3schools.com/HTMLDOM/dom_obj_document.asp

ChaosPandion
+2  A: 

The Window object is the top level object in the JavaScript hierarchy, so just refer to it as window

Kevin Hakanson
+1  A: 

You can go with document.defaultView if you want to exclude Microsoft browsers.

kennebec
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
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
IE only I see...
Crescent Fresh
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