【发布时间】:2014-06-10 03:20:37
【问题描述】:
我正在尝试从 iFrame 中删除内容,但我收到了这个 SO 问题:Unloading/Removing content from an iFrame。
问题是,当我尝试编写给出的解决方案时,我在 FireBug 的调试控制台上收到此错误:Permission denied to access property 'document'。
我正在做的是这样的:
var frame = document.getElementById("idFrame"),
frameDoc = frame.contentDocument || frame.contentWindow.document; //error here
frameDoc.removeChild(frameDoc.documentElement);
这里有什么问题?我做错了什么?
当我尝试做同样的错误:
$("#amadeusFrame").contents().find("body").html('');
【问题讨论】:
-
跨域访问?如果是,Same-origin policy 会阻止对 iframe 的访问。
-
就像@Teemu 所说的那样 - 阅读第三条评论以获取有关问题 Teemu 链接的已接受答案。如果你想清除 iframe 中的所有内容,当然可以试试我的解决方案。
标签: javascript html iframe