热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Firefox无法找到iframe-Firefoxnotabletofindiframe

ThisistheiframeImtryingtoaccess:这是我试图访问的iframe:<dividadditionalTxt

This is the iframe I'm trying to access:

这是我试图访问的iframe:

 

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.

出于某种原因,我从firebug得到“frames.additionalTxt_f未定义”。我在其他页面上有类似的iframe(由punyMCE插件动态创建),它们工作得很好。 IE7 / 8也可以访问这个iframe。

Just at a complete loss here. Any ideas on why Firefox can't find the iframe?

在这里完全失败了。关于Firefox无法找到iframe的任何想法?

2 个解决方案

#1


8  

The 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.

window.frames []数组由[i]帧的名称属性(也称为帧目标)索引。不能依赖id也可以工作 - 虽然它可能在IE <8中,它通常认为名称和ID是相同的东西。

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:

如果要通过ID访问框架的内容,请使用DOM Level 2 HTML contentDocument属性而不是old-school(“DOM Level 0”)框架数组:

document.getElementById('additionalTxt_f').contentDocument.body.innerHTML

...but then, for compatibility with IE <8, you also have to add some fallback cruft, since it doesn't support contentDocument:

...但是,为了兼容IE <8,你还必须添加一些后备,因为它不支持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.

因此,您认为哪种方法不那么难看:额外的脚本工作,或者仅使用name属性。

#2


1  

if you have only 1 iframe you can also find it with window.frames[1] or document.getElementsByTagName('iframe')[0]

如果您只有1个iframe,您也可以使用window.frames [1]或document.getElementsByTagName('iframe')[0]找到它

(In the first option, the parent window is #0)

(在第一个选项中,父窗口为#0)


推荐阅读
author-avatar
呼呼小琰琰
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有