Window. history. back (-1)
window.history.back();window.history.forward()window.history.go(-1)
Javascript: history. go (-1) and javascript: history. back (-1)Go (-1): return to the previous page. The content in the original page form will be lost. back (-1): return to the previous page. The content in the original page form will be retained.
Go (-1): return to the previous page. The content in the original page form will be lost. back (-1): return to the previous page. The content in the original page form will be retained.
<Input type = button value = Refresh onclick = "window. location. reload () "> <input type = button value = forward onclick =" window. history. go (1) "> <input type = button value = backward onclick =" window. history. go (-1) "> <input type = button value = forward onclick =" window. history. forward () "> <input type = button value = backward onclick =" window. history. back () ">
Backward + refresh <input type = button value = backward onclick = "window. history. go (-1); window. location. reload ()">
History. back () is the previous page
I = 1
History. go (I) goes to a specified page
If it is history. go (0), it is to refresh these two JS codes, which is equivalent to IE's forward and backward functions.
The specific use depends on when this is needed. For example, the user registration verification is background verification, and this can be used when the user does not meet the requirements, to ensure that the user does not input data repeatedly to the maximum extent.
For example, load a page:
Function onLoadPage (){
If (event. srcElement. tagName = "SPAN "){
OFrame = top. window. middle. frames [2];
OTxt = event. srcElement. innerText;
Switch (oTxt ){
Case "Forward ":
OFrame. history. go (1 );
Case "back ":
OFrame. history. back ();
Case "refreshing ":
OFrame. location. reload ();
}
}
}
If the button ID is LinkButton1
Protected void Page_Load (object sender, EventArgs e)
{
Int x = 0;
If (ViewState ["x"]! = Null)
{
X = (int) ViewState ["x"];
}
X ++;
ViewState ["x"] = x;
This. LinkButton1.Attributes. Add ("onclick", "window. history. go (-" + x + "; return false ");
}
Public static int GetPageRequestTimes ()
{
String sKey = System. Web. HttpContext. Current. Request. Url. LocalPath;
HttpCookie cookfrom = System. Web. HttpContext. Current. Response. Cookies [sKey];
String sTimes = cookfrom ["count"];
If (CCConvert. IsInt32 (sTimes) return Convert. ToInt32 (sTimes) + 1;
Else return 0;
}
Public static void SetBtnBackJs (System. Web. UI. HtmlControls. HtmlInputButton btn)
{
Int iTimes = (GetPageRequestTimes () *-1;
Btn. Attributes. Add ("onclick", "javascript: window. history. go (" + iTimes. ToString () + ");");
}
Public static void SavePageBackInfo (System. Web. UI. Page)
{
String sKey = page. Request. Url. LocalPath;
HttpCookie cookfrom = page. Request. Cookies [sKey];
If (cookfrom = null)
{
Cookfrom = new HttpCookie (sKey );
}
String sTimes = "0 ";
If (page. IsPostBack)
{
STimes = cookfrom ["count"];
STimes = (Convert. ToInt32 (sTimes) + 1). ToString ();
}
Cookfrom ["count"] = sTimes;
Page. Response. Cookies. Add (cookfrom );
}