使用getElementById刷新iframe父页面

使用getElementById刷新iframe父页面,iframe,get,Iframe,Get,当iframe包含指定的div id时,是否只能刷新一次iframe父页面 我在父页面上尝试了此操作,但没有成功: if document.frames('myiframe').(document.getElementById("iframedivID") !== null) { window.location.href = "mysite.com"; } 加载内部文档需要时间。因此,我们必须等待内部文档被加载,一旦加载,就可以访问内部div。下面是我的示例HTML和javascript代码

当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>
<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>

Test1.html

<iframe id="iframedivID" src="Test1.html"></iframe>
<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>
我叫拉文德拉
if(window.parent.window.location.href.toString().indexOf(“?刷新”)=-1){
window.parent.window.location.href=“Test.html?刷新”;
}

不工作。我尝试了同样的结果,如果($('expectedID')[0]){window.top.location=“”}Null警报不断出现,即使在同一页面上也无法工作。似乎test.html在iframe中找不到'myDiv',因此不会触发任何事件,可能是因为父页面先加载,iframe1-2秒后加载?两个HTML都保存了吗?在同一文件夹中?它们位于同一域的服务器上。