This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

popstate

Summary

An event handler that is fired when changes are made to the active history. Calls to pushState or replaceState can trigger this event.

Overview Table

Synchronous No
Bubbles Yes
Target dom/Element
Cancelable No
Default action None
## Examples
window.onpopstate = function(event) {
  alert("location: " + document.location + ", state: " + JSON.stringify(event.state));
};
history.pushState({page: 1}, "title 1", "?page=1");
history.pushState({page: 2}, "title 2", "?page=2");
history.replaceState({page: 3}, "title 3", "?page=3");
history.back(); // alerts "location: http://example.com/example.html?page=1, state: {"page":1}"
history.back(); // alerts "location: http://example.com/example.html, state: null
history.go(2);  // alerts "location: http://example.com/example.html?page=3, state: {"page":3}

Syntax

Event handler parameters

val [in]
Type: Function A script function to do something when the event is fired.

Attributions