A simple example of how to use Window.location.hash to implement the browser's forward/backward function when Ajax is being manipulated

Source: Internet
Author: User
Tags call back

We know that Window.history objects are provided early in JavaScript, and that the forward (), go (), and Back () methods of the History object can be used to facilitate such navigation functions as forward and backward between different pages. However, Ajax operations cannot be navigated with the browser's forward and backward buttons, because the browser does not add AJAX operations to the history. But with Location.hash, we are able to move forward and backward on our own AJAX operations. For more information about Window.location.hash and how to use them, refer to these 2 articles below.

Location.hash detailed and 6 things should Know about Fragment URLs.

We need to know the following 2 points:

1. If the location.hash changes, the URL of the browser address bar will change and the browser will generate 1 historical records.

2. If the location.hash has changed, a Hashchange event will be generated and we can handle the event.

<! DOCTYPE html> 


Run this HTML file under Chrome, default to the home page, and click on the button to call back to the next page (until the last page). We can click on the browser's forward and backward buttons to simulate the function of Ajax forward and backward.




A simple example of how to use Window.location.hash to implement the browser's forward/backward function when Ajax is being manipulated

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.