我想重新加载一个<iframe>使用JavaScript。到目前为止,我发现最好的方法是将iframe的src属性设置为自身,但这不是很干净。什么好主意吗?
当前回答
从Iframe内部重新加载
如果你的应用程序在Iframe中,你可以通过替换位置href来刷新它:
document.location.href = document.location.href
其他回答
在IE8中使用。net,设置iframe。SRC第一次是可以的, 而是设置iframe。SRC第二次没有引发iframed页面的page_load。 为了解决这个问题,我使用了iframe.contentDocument.location.href = "NewUrl.htm"。
当使用jQuery thickBox并尝试在thickBox iframe中重新打开同一页面时发现它。 然后它只显示之前打开的页面。
<script type="text/javascript">
top.frames['DetailFrame'].location = top.frames['DetailFrame'].location;
</script>
如果使用jQuery,这似乎是可行的:
$('#your_iframe').attr('src', $('#your_iframe').attr('src'));
将空字符串附加到iFrame的src属性也会自动重新加载它。
document.getElementById('id').src += '';
IE使用reload,其他浏览器使用set src。(重新装填对FF无效) 在IE 7、8、9和Firefox上测试
if(navigator.appName == "Microsoft Internet Explorer"){
window.document.getElementById('iframeId').contentWindow.location.reload(true);
}else {
window.document.getElementById('iframeId').src = window.document.getElementById('iframeId').src;
}