HTML5 new features: use history. replaceState () to modify the history, html5replacestate

Source: Internet
Author: User

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.


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.