HTML-如何刷新Iframe



我已经创建了一个Iframe,它现在对我有效,唯一的问题是当我单击我在Iframe中创建的刷新图标时,它不起作用,并且我得到错误Uncaught TypeError:无法读取null 的属性'src'

这是我的代码:

function refreshIframe() {
document.getElementById('iframeID').src = document.getElementById('iframeID').src;
}
function displayIframe() {
document.getElementById("iframeID").innerHTML = "<iframe src='https://www.google.com/' height="100%" width="100%" ></iframe>";
}
<button onclick="displayIframe()">Display</button>
<div id="iframeID">
<div onclick="refreshIframe()">
<img src="./refresh.png" />
</div>
</div>

我想做的只是刷新iframe

您正在框架页面内尝试获取父页面中存在的元素。我已经向你展示了如何联系家长做这样的事情:

HTML-删除iframe显示

或者,你可以做

function refreshIframe() {
window.location = window.location;
}

最新更新