HTML5 History API

Source: Internet
Author: User

With HTML5 history API for keyword search, will get a lot of results, I only according to their own use collation.

1, two API

Pushstate and Replacestate.

Pushstate adds a state to the browser's history for use when the browser backs forward

History.pushstate (data, ' page title ', URL);

Replacestate is to replace a state with the same parameters as the pushstate.

2. An event

Onpopstate.

The user clicks forward or backward to trigger, rather than when using pushstate or replacestate. The function is to detect if the state changes, and then we can customize the logic.

function (e) {    // your code }

The event argument e contains the State property, which is the status of your push or replace.

Note: These two API knowledge changed the URL of the page, the specific logic to implement their own, generally according to state to enter the Ajax, sometimes not reliable, that is based on the URL.

In particular, users refresh the page, will prompt the page does not exist, so need to just enter the page according to the URL or hash to judge, display the corresponding content.

http://www.zhangxinxu.com/wordpress/2013/06/html5-history-api-pushstate-replacestate-ajax/Here is a good example.

HTML5 History API

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.