Javascript HTML-iframe重新加载和父级重新加载之间的差异
在“myIframe”中: 重新加载Iframe时,不会执行此页面中的javascript: myIframe:Javascript HTML-iframe重新加载和父级重新加载之间的差异,javascript,html,Javascript,Html,在“myIframe”中: 重新加载Iframe时,不会执行此页面中的javascript: myIframe: alert("reloaded"); $('.selectedTab').click(function() { document.getElementById("myIFrame").contentDocument.location.reload(true); }); 但是如果我重新加载它的父页面,javascript就会重新加载 parent.location.relo
alert("reloaded");
$('.selectedTab').click(function() {
document.getElementById("myIFrame").contentDocument.location.reload(true);
});
但是如果我重新加载它的父页面,javascript就会重新加载
parent.location.reload();
这两种方法的区别是什么
可以在不经过父页面和不请求服务器的情况下重新加载Iframe contain,只需“重播”已获取的数据 正如Kevin B提到的,这似乎是内容位置的问题。确保Iframe src也来自与父级相同的域 -对我来说似乎很好
<script>
window.onload = function() {
alert("reloaded");
$('.selectedTab').click(function() {
document.getElementById("myIFrame").contentDocument.location.reload(true);
});
}
</script>
<button class="selectedTab">Reload Iframe</button>
<iframe id="myIFrame" src="/" />
window.onload=函数(){
警报(“重新加载”);
$('.selectedTab')。单击(函数(){
document.getElementById(“myIFrame”).contentDocument.location.reload(true);
});
}
重新加载Iframe
困惑。。。javascript在哪里?到目前为止,您展示的javascript看起来像是父页面上的代码,当然,除非您重新加载父页面,否则不会重新执行。正如我提到的,javascript存在于iframe中如果它在iframe中。。。document.getElementById(“myIFrame”).contentDocument.location.reload如何重新加载(true)代码>从iframe内部定位iframe?实际上,我想在我所在的位置重新加载iframe。只要在脚本位于iframe内时执行window.location.reload(…)
。事实上,“按钮”位于“myIframe”内