我在 div block 中使用 iframe,并尝试使用以下代码通过单击按钮来更改其 src。
function helloClick(){
var iframe = document.getElementById("iframeDiv");
iframe.src = "hello_world";
iframe.contentDocument.location.reload(true);
}
hello_world 文件与定义 iframe 的文件位于同一文件夹中。每次单击该按钮时都会收到以下错误消息。
Uncaught TypeError: Cannot read property 'location' of undefined
如何解决这个问题?
最佳答案
尝试下面的代码片段
function helloClick(){
var iframe = document.getElementById("iframeDiv");
iframe.src = "hello_world";
iframe.src = iframe.src;
}
应该对你有帮助。
关于javascript - 刷新iframe错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35263312/