码迷,mamicode.com
首页 > Web开发 > 详细

jsp页面跳转

时间:2014-05-25 09:36:56      阅读:387      评论:0      收藏:0      [点我收藏+]

标签:style   class   c   java   tar   ext   

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=刷新 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()">
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();
}
}
}



如果按钮的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);

        }

jsp页面跳转,布布扣,bubuko.com

jsp页面跳转

标签:style   class   c   java   tar   ext   

原文地址:http://blog.csdn.net/xad707348125/article/details/26875571

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!