HTML5 new features: use history. replaceState () to modify the history, html5replacestate
When we introduced history. pushState () in the previous article, we mentioned three problems in location. hash. The first problem: the url will change, which is easy to understand. Now let's take a look at the second and third questions, that is, how to modify the browser's historical records and how to store more state-related information. Status-related information the previous blog has easily seen that the first parameter of history. pushState () is a javascript Object. Of course, we can store any data we want in this object. This document describes how to use histroy. replaceState to modify the browsing history.
Or the example in the previous article, if we want to implement this function: display the number of times this page is accessed on the current page. Obviously, through the browser's forward and backward buttons, we can access a page Infinitely multiple times. But we do not want to generate more historical records, Because I jumped over before page A and page B. To put it bluntly, there are two historical records, but the page information has changed. PushState and location. hash cannot meet this requirement, because both methods generate new historical records and cannot modify existing historical records. At this time, replaceState will be useful.
<! DOCTYPE html>
In the onpopstate event processing function, we get the status information of the Current History, and then use replaceState to modify the status information. In this way, we modified the status information (modified the history), but did not generate a new record. This cannot be implemented using pushState and location. hash.