views:

116

answers:

2

In javascript how do I get a handle on the frame that I'm in based on an element in that frame?

function myFunction(elementInFrame){
   // here I want to get a handle on the frame that elementInFrame lives in
}
+1  A: 

In IE you can do elementInFrame.document.parentWindow Doesn't work in Firefox unfortunately.

Edit: If you're using frames then in FF you could do it the long way... loop through all the frames until you find the element you're looking for.

Greg
I don't think the looping solution will work in my case because I don't want my function to know anything about the frame it's looking for.
Aaron Palmer
+2  A: 

elementInFrame.document.defaultView for non-IE browsers.

(It's not quite a standard part of the DOM; DOM Level 2 Views says the property exists but doesn't explicitly say it points to ‘window’, since the DOM standard currently known nothing about the window object.)

bobince