跟大家講解下有關Javascript刷新頁面方法及location.reload()用法介紹,相信小伙伴們對這個話題應該也很關注吧,現在就為小伙伴們說說Javascript刷新頁面方法及location.reload()用法介紹,小編也收集到了有關Javascript刷新頁面方法及location.reload()用法介紹的相關資料,希望大家看到了會喜歡。
本文主要和大家介紹Javascript刷新頁面方法及location.reload()用法介紹,希望通過本文能幫助到大家,需要的朋友可以參考下,希望能幫助到大家。Javascript刷新頁面的幾種方法:
1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(location) 5 document.execCommand('Refresh') 6 window.navigate(location) 7 location.replace(location) 8 document.URL=location.href
自動刷新頁面的方法:
1.頁面自動刷新:把如下代碼加入<head>區域中
<meta http-equiv="refresh" content="20">其中20指每隔20秒刷新一次頁面.
2.頁面自動跳轉:把如下代碼加入<head>區域中
<meta http-equiv="refresh" content="20;url=http://www.wyxg.com">其中20指隔20秒后跳轉到http://www.wyxg.com頁面
3.頁面自動刷新js版
<mce:script language="JavaScript"><!-- function myrefresh() { window.location.reload(); } setTimeout('myrefresh()',1000); //指定1秒刷新一次 // --></mce:script>在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() { (php中文網 www.php.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();相關推薦:
Javascript中刷新頁面的示例詳解
利用JavaScript實現不刷新頁面預覽上傳圖片方法教程
JS刷新頁面總和!多種JS刷新頁面代碼!
以上就是Javascript刷新頁面方法及location.reload()用法介紹的詳細內容,更多請關注php中文網其它相關文章!
來源:php中文網