天天看點

javascript:history.go()和History.back()的差別

<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,因在按鈕事件觸發前,已重新整理一次頁面,是以應是-2。

Response.Write("<script language=javascript>history.go(-2);</script>");

此處也要寫為“-2”。跟直接寫腳本的有所不同。history.back()是會上一頁

i=1

history.go(i)去指定的某頁

如果是history.go(0)那就是重新整理這兩個屬于JS代碼,相當于IE的前進、後退功能。

具體的用處就要看什麼時候需要這個就用上。比如使用者注冊時的驗證是背景驗證,不符合要求的時候就可以用這個,可以最大限度保證使用者少重複輸入資料。

例如:載入頁面:

   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