Javascript: The difference between history. go () and History. back () and Its Application

Source: Internet
Author: User

Copy codeThe Code is as follows:
<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 () "> back + refresh <input type = button value = back onclick =" window. history. go (-1); window. location. reload () ">

In the C # Web program, for example, for the page button writing back to the previous page code
Copy codeThe Code is as follows:
This. RegisterClientScriptBlock ("E", "<script language = javascript> history. go (-2); </script> ");

Among them, history. go (-2) should be written as-2. Because the page has been refreshed once before the button event is triggered, it should be-2.
Copy codeThe Code is as follows:
Response. Write ("<script language = javascript> history. go (-2); </script> ");

It must also be written as "-2 ". It is different from writing scripts directly. History. back () is the previous page
Copy codeThe Code is as follows:
I = 1
History. go (I)
[Html]
Go 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:
[Code]
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 ();
}
}
}

To open a jsp page, you must have refreshed it using a client script.
How to refresh the page with Javascript:
Copy codeThe Code is as follows:
1 history. go (0)
2 location. reload ()
3 location = location
4 location. assign (location)
5 document.exe cCommand ('refresh ')
6 window. navigate (location)
7 location. replace (location)
8 document. URL = location. href

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.