javascript:history.go()和History.back()的區(qū)別及應(yīng)用
更新時間:2012年11月25日 13:00:01 作者:
為提高用戶體驗度,可能會使用到刷新 前進 后退等相關(guān)更能,本文將以此問題詳細介紹javascript:history.go()和History.back()的區(qū)別及應(yīng)用,需要的朋友可以參考下
復制代碼 代碼如下:
<input type=button value=刷新 onclick="window.location.reload()">
<input type=button value=前進 onclick="window.history.go(1)">
<input type=button value=后退 onclick="window.history.go(-1)">
<input type=button value=前進 onclick="window.history.forward()">
<input type=button value=后退 onclick="window.history.back()"> 后退+刷新<input type=button value=后退 onclick="window.history.go(-1);window.location.reload()">
在C# Web程序中,如為頁面按鈕寫返回上一頁代碼
復制代碼 代碼如下:
this.RegisterClientScriptBlock("E", "<script language=javascript>history.go(-2);</script>");
其中,history.go(-2),要寫為-2,因在按鈕事件觸發(fā)前,已刷新一次頁面,所以應(yīng)是-2。
復制代碼 代碼如下:
Response.Write("<script language=javascript>history.go(-2);</script>");
此處也要寫為“-2”。跟直接寫腳本的有所不同。history.back()是會上一頁
復制代碼 代碼如下:
i=1
history.go(i)
[html]
去指定的某頁
如果是history.go(0)那就是刷新這兩個屬于JS代碼,相當于IE的前進、后退功能。
具體的用處就要看什么時候需要這個就用上。比如用戶注冊時的驗證是后臺驗證,不符合要求的時候就可以用這個,可以最大限度保證用戶少重復輸入數(shù)據(jù)。
例如:載入頁面:
[code]
function onLoadPage(){
if(event.srcElement.tagName=="SPAN"){
oFrame=top.window.middle.frames[2];
oTxt=event.srcElement.innerText;
switch(oTxt){
case "前 進":
oFrame.history.go(1);
case "后 退":
oFrame.history.back();
case "刷 新":
oFrame.location.reload();
}
}
}
打開一個jsp頁面,肯定是用客戶端腳本進行刷新了。
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
相關(guān)文章
javascript this指向相關(guān)問題及改變方法
這篇文章主要介紹了javascript this指向相關(guān)問題及改變方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-11-11javascript實現(xiàn)漢字轉(zhuǎn)拼音代碼分享
這篇文章主要介紹了javascript實現(xiàn)漢字轉(zhuǎn)拼音代碼分享,非常的實用,從項目中分離出來的,這里分享給大家,有需要的小伙伴可以參考下。2015-04-04javascript實現(xiàn)依次輸入input自動定焦
這篇文章主要介紹了javascript實現(xiàn)依次輸入input自動定焦的方法及示例代碼,非常實用,這里推薦給小伙伴們2014-12-12