Javascript / selenium: get the window from the document object

documentdomfirefoxjavascriptselenium

I am writing user extensions to selenium. I have the document object. How can I get the window object of the window that contains my document?

PageBot.prototype.locateElementByMyLocator= function(text, inDocument) {
     // I want the window here
}

Best Answer

In IE it's document.parentWindow; in Mozilla it's document.defaultView.

Thus you could do something like

function getDocWindow(doc) {
  return doc.parentWindow || doc.defaultView;
}