我想重新加载一个<iframe>使用JavaScript。到目前为止,我发现最好的方法是将iframe的src属性设置为自身,但这不是很干净。什么好主意吗?


当前回答

<script type="text/javascript">
  top.frames['DetailFrame'].location = top.frames['DetailFrame'].location;
</script> 

其他回答

从Iframe内部重新加载

如果你的应用程序在Iframe中,你可以通过替换位置href来刷新它:

document.location.href = document.location.href

如果使用jQuery,这似乎是可行的:

$('#your_iframe').attr('src', $('#your_iframe').attr('src'));

出于调试目的,可以打开控制台,将执行上下文更改为他想要刷新的帧,然后执行document.location.reload()

window.frames['frameNameOrIndex'].location.reload();

新url

location.assign("http:google.com");

assign()方法加载一个新文档。

重新加载

location.reload();

reload()方法用于重新加载当前文档。