history.go(-1); // 返回上一頁 history.go(-2); // 返回前兩頁 history.back(); // 等同返回上一頁 window.history.forward(); // 前進一頁 window.history.go(n); // 跳到第 n 頁,也可傳入走訪過的 URL
實際應用在連結上:
<a href="javascript:history.go(-1);">向上一頁</a>
搭配確認視窗使用,讓使用者可以取消返回:
response.Write("<script language=javascript>")
response.Write("if(!confirm('完成任務?')){history.back();}")
response.Write("</script>")
response.Write("<script language=javascript>history.go(-1);</script>")
頁面跳轉則用:
onclick="window.location.href='list.aspx'"
history.go(0)
location.reload()
location = location
location.assign(location)
document.execCommand('Refresh')
window.navigate(location)
location.replace(location)
document.URL = location.href
把 meta 標籤放進 <head> 區域即可。每 20 秒重新整理一次:
<meta http-equiv="refresh" content="20">
20 秒後跳轉到指定網址:
<meta http-equiv="refresh" content="20;url=https://www.javaeye.com">
用 JavaScript 實作定時重新整理:
<script language="JavaScript">
function myrefresh()
{
window.location.reload();
}
setTimeout('myrefresh()',1000); //指定1秒刷新一次
</script>
ASP.NET 中輸出刷新父視窗的語法:
1. this.response.write("<script>opener.location.reload();</script>");
2. this.response.write("<script>opener.window.location.href = opener.window.location.href;</script>");
3. Response.Write("<script language=javascript>opener.window.navigate('你要刷新的頁.asp');</script>")
刷新包含該框架的頁面:
<script language=JavaScript> parent.location.reload(); </script>
子視窗刷新父視窗:
<script language=JavaScript> self.opener.location.reload(); </script>
刷新另一個框架中的頁面:
<script language=JavaScript> parent.另一FrameID.location.reload(); </script>
想在開窗或關窗時觸發刷新,直接在 <body> 上掛事件即可:
<body onload="opener.location.reload()"> <!-- 開窗時刷新 --> <body onUnload="opener.location.reload()"> <!-- 關閉時刷新 --> <script language="javascript"> window.opener.document.location.reload() </script>
需要確認某個函式庫是否已載入,再決定要不要補上腳本時,可以這樣寫:
<script type=text/javascript>
<!--
if (typeof SWFObject == "undefined") {
document.write('<scr' + 'ipt type="text/javascript" src="/scripts/swfobject-1.5.js"></scr' + 'ipt>');}
//-->
</script>
把 <script> 拆成字串拼接,是為了避開 HTML 解析器把註解內的結束標籤提前判讀的問題。