The HTML DOM PopStateEvent is an event handler for the popstate event on the window. A popstate event is dispatched to the window every time the active history entry changes between two history entries for the same document.
Property:
Event Types:
Example:
<!DOCTYPE html> < html >
< body >
< script >
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");
// alerts "location:
// state: {"page":1}"
history.back();
// alerts "location: about:blank, state: null"
history.back();
</ script >
</ body >
</ html >
|
Output:
Supported Browsers:
- Google Chrome
- Mozilla Firefox
- Opera
- Edge
- Safari