Use the history. pushState () and popstate events to implement the AJAX forward and backward functions. pushstateajax

Source: Internet
Author: User

Use the history. pushState () and popstate events to implement the AJAX forward and backward functions. pushstateajax

In the previous article, we used location. hash to simulate the ajax forward and backward functions. Using location. hash has the following problems:

1. Using location. hash will change the url in the address bar and the user experience is unfriendly.

2. historical records generated by location. hash cannot be modified. Each hash change will generate a new historical record.

3. location. hash is only a string and does not store much state-related information.

To solve these problems, HTML5 introduces history. pushState (), history. replaceState (), and popstate events to process browser history. The following code achieves the same effect as location. hash. You can see that the url in the address bar does not change.

<! DOCTYPE html> 




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.