Home > Web Front-end > JS Tutorial > Solution to the problem that js cannot jump to the previous page_javascript skills

Solution to the problem that js cannot jump to the previous page_javascript skills

WBOY
Release: 2016-05-16 17:41:20
Original
1238 people have browsed it
Problem description: We have two pages A and B. When we jump from A to B, we can return to it using JS: history.go(-1) without doing any operations to post the page back. Page A, but for example, we have Click, Change events, etc. that trigger the postback of the page. At this time, using history.go(-1) will not return to page A.

Solution: We need to find a way to record the number of page postbacks N, and then use history.go(-n) to return to page A.
Put a control in page B to record the number of postbacks. The initial value is 1.
Copy the code The code is as follows:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>




<script> <br>function goto() { <br>var n=document.getElementById("TextBox1").value; <br>var n=Number(n); <br>history.go(-n); <br>} <br></script>






1





The CS code on page B is as follows:
Copy code The code is as follows:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.TextBox1.Text = "1";
}
else
{
this.TextBox1.Text = Convert.ToString( Convert.ToInt16(this.TextBox1.Text) 1);
}
}

In this way, no matter what operations you do on page B from A to B, the page No matter how many times you have posted back, when you click [Return], you can jump back to page A
Source code download
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template