history onpopstate code example
Example: javascript window.onpopstate example
window.onpopstate = function(event) {
alert("location: " + document.location + ", state: " + JSON.stringify(event.state));
const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('myParam');
};
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();
history.back();
history.go(2);