window.history.back(-1)
window.history.back(); window.history.forward() window.history.go(-1)
javascript:history.go(-1)和javascript:history.back(-1)
go(-1): 返回上一页, 原页面表单中的内容会丢失; back(-1): 返回上一页, 原页表表单中的内容会保留.
go(-1): 返回上一页, 原页面表单中的内容会丢失; back(-1): 返回上一页, 原页表表单中的内容会保留.
<input type=button value=刷新 οnclick="window.location.reload()"> <input type=button value=前进 οnclick="window.history.go(1)"> <input type=button value=后退 οnclick="window.history.go(-1)"> <input type=button value=前进 οnclick="window.history.forward()"> <input type=button value=后退 οnclick="window.history.back()">
后退+刷新<input type=button value=后退 οnclick="window.history.go(-1);window.location.reload()">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();
}
}
}
假设button的ID是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 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);
}
{
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 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);
}