在javascript編程中,多使用location.reload實現頁面刷新。
例子:
代碼示例:
window.location.href=window.location.href;
window.location.reload;
經測試,這兩句在某些情況下可以代替location.reload(true);
而不會出現重試對話框達到刷新的效果
在js中實現刷新頁面的方法有很多種,在js中有一個location.reload()函數,它就可以實現我們想要的功能。
window.location.reload(true) //瀏覽器重新從服務器請求資源,在http請求頭中不會包含緩存標記。
例1,刷新當前頁面
代碼示例:
<script>
window.location.reload();
</script>
例2,JS實現刷新iframe的方法
用iframe的name屬性定位
代碼示例:
<input type="button" name="Button" value="Button" onclick="document.frames('ifrmname').location.reload()">
或
<input type="button" name="Button" value="Button" onclick="document.all.ifrmname.document.location.reload()">
例3,首先,定義一個iframe
代碼示例:
<iframe method="post" id ="IFrameName" src="aa.htm" ></iframe>
aa.htm頁面的內容:
代碼示例:
<input type ="button" value ="刷新" onclick ="aa()"/> function aa() { (jquery中文網 www.jquerycn.cn 編輯整理) //parent.location.replace(parent.location.href);//服務器端重新創建頁面 parent.document.location.reload();//相當於F5 //window.location.href(parent.location.href);//iframe內容重定向 }
注意:
window.location.reload;
刷新時如果提交數據的動作,則會出現對話框!
解決辦法:
代碼示例:
window.location.href=window.location.href;
window.location.reload;
刷新父窗口:
代碼示例:
window.opener.location.href=window.opener.location.href;
window.opener.location.reload();
摘自: http://www.jquerycn.cn/a_11620