当 iframe 包含指定的 div id 时,是否可以只刷新一次 iframe 父页面?
我在父页面上尝试过此操作,但没有成功:
if document.frames('myiframe').(document.getElementById("iframedivID") !== null) { window.location.href = "mysite.com"; }
最佳答案
加载内部文档需要一些时间。所以我们必须等到内部文档加载完毕,一旦加载完毕,就可以访问内部 div 了。这是我的示例 HTML 和 javascript 代码。因此,您可能第一次在警报中收到null。希望这会有所帮助。
Test.html
<iframe id="iframedivID" src="Test1.html"></iframe>
Test1.html
<div id='myDiv'>My name is ravindra</div>
<script type="text/javascript">
if (window.parent.window.location.href.toString().indexOf("?refresh") == -1){
window.parent.window.location.href="Test.html?refresh";
}
</script>
关于iframe - 使用 getElementById 刷新 iframe 父页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15363128/