現在很多網站里都有上一頁和下一頁的功能,這樣可以提高網站的用戶體驗度,那么用CMS系統建站,應該如何實現呢?下面六種方法可以幫助您!
方法一:
在asp.net的aspx里面的源代碼中,注意:這個是用了HTML控件,通過一個onclick的事件,調用了javascript中的一個方法就可以了。這個是最簡單的了,也同樣適用于靜態頁面,ASP頁面等。
<input type="button onclick="javascript:window.history.go(-1);"value="返回上一頁">
方法二:Response.Write("<script>alert(’提示信息’);history.back()</script>");
Response.Write("<script>alert(’提示信息’);top.location.href=’" + PageURL + "’</script>")
Response.Write("<script>alert(’提示信息’);window.location.href=’" + PageURL + "’</script>");
Response.Write("<script>alert(’提示信息’);window.location=window.location;</script>");
方法三:在button的onClick事件中輸入
this.RegisterClientScriptBlock("e", "<script language=javascript>history.go(-2);</script>");
方法四:利用Reponse.write
Response.write("<script language=javascript>history.go(-2);</script>)
<a href="#" onclick="javascript:history.back();">返回前一頁</a>
方法五:
<a href=<%=request.servervariable("http_Referre)%>
<asp:image id="imageback" visible = true" imagurl="上一頁" runat="server"/></a>
方法六:利用Response.Redirect() 或 server.transfer()
在page_load中加入
if(!IsPostBack)
ViewState["retu"]=Request.UrlReferrer.ToString();
而在在返回按鈕事件中
Response.Redirect(ViewState["retu"].ToString());或Server.Transfer (ViewState["retu"].ToString());
在使用Request.UrlReferrer時還要注意:
1. 如果上一頁面使用document.location方法導航到當前頁面,Request.UrlReferrer返回空值
2. 點擊刷新按鈕不會改變Request.UrlReferrer
3. 用CMS建A,B兩個頁面,在瀏覽器中直接請求A頁面,在A頁面的中Page_Load事件中導航到B 頁面,則 Request.UrlReferrer返回空。因為 在Page_load事件中頁面還未初始化,所以無法記錄當前頁的信息,導航到b頁面也就無法獲得上一頁面的信息