【发布时间】:2011-06-30 08:53:40
【问题描述】:
我希望这里有人能够提供帮助,我先谢谢了。
我有一个 iframe(在我的域中),当有人单击 iframe 中的链接时,我不希望该链接自动打开,我需要它转到一个功能,在添加一些内容后导航到该链接页。
我用这个函数来填充 iframe
function setIframeHtml(html) {
var iframe = document.getElementById("myFrame");
var doc = iframe.document;
if (iframe.contentDocument) {
doc = iframe.contentDocument; // For NS6
}
else if (iframe.contentWindow) {
doc = iframe.contentWindow.document; // For IE5.5 and IE6
}
// Put the content in the iframe
doc.open();
doc.writeln(html);
doc.close();
navigating = false;
}
函数获取的html参数是添加我的东西后要加载的页面。
当我从 iframe 内部执行此操作时,我收到一条错误消息
Cannot read property 'document' of null
只有当我从外部调用该函数时,如果 iframe,它才起作用。
任何想法如何使它工作?
【问题讨论】:
标签: javascript html iframe anchor