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>