admin管理员组文章数量:1313347
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 plete loss here. Any ideas on why Firefox can't find the iframe?
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 plete loss here. Any ideas on why Firefox can't find the iframe?
Share Improve this question asked Apr 6, 2009 at 10:03 peirixpeirix 37.8k24 gold badges98 silver badges130 bronze badges2 Answers
Reset to default 8The window.frames[]
array is indexed by the [i]frame's name
attribute (aka frame target). id
can'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 contentDocument
property instead of the old-school (“DOM Level 0”) frames
array:
document.getElementById('additionalTxt_f').contentDocument.body.innerHTML
...but then, for patibility with IE <8, you also have to add some fallback cruft, since it doesn't support contentDocument
:
var f= document.getElementById('additionalTxt_f');
var d= f.contentDocument? f.contentDocument : f.contentWindow.document;
d.body.innerHTML
So it's up to you which method you think is less ugly: the extra script work, or just using the name
attribute.
if you have only 1 iframe you can also find it with window.frames[1] or document.getElementsByTagName('iframe')[0]
(In the first option, the parent window is #0)
本文标签: javascriptFirefox not able to find iframeStack Overflow
版权声明:本文标题:javascript - Firefox not able to find iframe - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741943520a2406281.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论