Use JavaScript's history object to implement page forward backward (Go/back/forward).

Source: Internet
Author: User

We all know that JavaScript has a History object, which is mainly used to record the browser window's browsing history. However, the JS script is not allowed to access the contents of this record (privacy).

The common usage is:

History.back ();//returns to the previous page, equivalent to the browser fallback function.

History.forward ();//Go to the next page, equivalent to the browser's forward function.

Histoty.go (int);//go to the specified browsing history page. int is positive, it is forward int history record, if not so many, there is no behavior. int is negative, then it's backwards.

back int records, if there are not so many times, there is no behavior. 0 I tried it without any action.

Note: The above 3 methods do not refresh the page as explained by the results you went to Baidu, which is incorrect. After I went to StackOverflow to view, but also refer to the "JavaScript authoritative guide",

Indicates that the new document is not refreshed to load. In the JavaScript authoritative guide, it is clear that modern browser applications can dynamically change their content without loading new documents. So, if it is

If you want to refresh the page state after History.back () or Histoty.go (-1), I'm sorry, we can't finish the task simply by using the history object.

After the experiment, JS's location object after using History.back (), does not mean History.back () this page, but the call History.back () This method when the page. So I want to pass the simple

Location.reaload () will not work to refresh the page. Similarly, the other several JS Refresh method is similar to the situation.


Use JavaScript's history object to implement page forward backward (Go/back/forward).

Related Article

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.