This is the iframe I’m trying to access:
<div class='mceBody' id='additionalTxt_b'> <iframe frameborder='0' id='additionalTxt_f' src='javascript:''' class='punymce'/> </div>
Using this line:
frames['additionalTxt_f'].document.getElementsByTagName('body')[0].innerHTML
For some reason I’m getting ‘frames.additionalTxt_f is undefined’ from firebug. I have similar iframes (dynamically created by punyMCE plugin) on other pages, and they work perfectly fine. And IE7/8 has no problem accessing this iframe either.
Just at a complete loss here. Any ideas on why Firefox can’t find the iframe?
The
window.frames[]array is indexed by the [i]frame’snameattribute (aka frame target).idcan’t be relied upon to also work — although it may in IE <8, which often thinks names and ids are the same thing.If you want to access a frame’s content via ID, use the DOM Level 2 HTML
contentDocumentproperty instead of the old-school (“DOM Level 0”)framesarray:…but then, for compatibility with IE <8, you also have to add some fallback cruft, since it doesn’t support
contentDocument:So it’s up to you which method you think is less ugly: the extra script work, or just using the
nameattribute.