Is it possible to access the window object directly from the document object in Javascript?
For example:
// window.frames[0] returns the document object of the first frame or iframe found on the page
myFunc(window.frames[0]);
function myFunc(doc) {
// I want to do something along these lines:
var wnd = doc.getWindow();
alert("Found frame: " + wnd.name);
for (var i=0; i<wnd.frames.length; i++) {
myFunc(wnd.frames[i]);
}
}
I can’t use jQuery for this, sorry.
According to the MDN documentation you should already be getting the window with
window.frames[0]. If you want the actual document you need to grab the actual frame element and dig into the document.Note: I believe
contentWindowisn’t supported in very early versions of Safari (pre-3.0 IIRC)