Help me get a handle on my frames!
October 31, 2008 8:00 PM
Subscribe
HTML/DOM/JavaScriptfilter: Help me get a handle on my frames! I'm by no means a javascript expert, though I can bash my way around in it when necessary - but I just can't figure out how to get a handle on the frames in my document via the DOM.
I'm trying to wrapper a pre-written app that I host (but have no control over and can't modify) in an IFRAME (for a couple of reasons), and want to register event handlers programatically on the frames of the app (to detect when the user is active in the app). The resultant page looks somewhat like
this. I'm trying to register event handlers on the nav and view frames from JavaScript in the top-level document, but cannot figure out how to traverse the DOM to get an object for the documents within the frames. I can't even use getElementById, because there are no IDs defined on the frames within the app. (But I'd rather have a generic solution that will work no matter what the frames are named.) FireBug is providing me with no assistance on this one, either. Can any of you MeFi HTML DOM wizards out there help?
posted by jferg to computers & internet (7 comments total)
2 users marked this as a favorite
window.framesget an array of all the frames/iframes, then dig through the array to find the right ones (hopefully your app doesn't create them in a different order in each page!). Once you've found the right ones in the array, it's then a matter of using something likewindow.frames[x].document.propertyto access them (e.g.window.frames[1].document.titlereturns the first iframe's title).(Don't quote me on that, though, because the last time I did this iframes were a new invention, and the whole DOM thing was very immature...)
posted by Pinback at 10:48 PM on October 31, 2008