Skip to content

Instantly share code, notes, and snippets.

@procarrera
Created August 29, 2021 19:36
Show Gist options
  • Save procarrera/8caa0e8d6cb1e8ed7c911050a3008f35 to your computer and use it in GitHub Desktop.
Save procarrera/8caa0e8d6cb1e8ed7c911050a3008f35 to your computer and use it in GitHub Desktop.
Add Query String to URL and fire event every time it changes
// Add query string to URL
const newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?step=1';
window.history.pushState({path:newurl},'',newurl);
// Fire event everytime state changes
window.addEventListener('popstate', function (event) {
console.log(event)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment