Skip to content

Instantly share code, notes, and snippets.

@esedic
Created January 17, 2024 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esedic/8c4491460779730e4a2300a968a9dd4f to your computer and use it in GitHub Desktop.
Save esedic/8c4491460779730e4a2300a968a9dd4f to your computer and use it in GitHub Desktop.
Remove URL parameters and reload page
function removeParamAndRefresh(paramToRemove) {
const url = new URL(window.location.href);
if (url.searchParams.has(paramToRemove)) {
url.searchParams.delete(paramToRemove);
// Update the URL in the address bar without reloading
window.history.pushState({}, '', url);
// Now, reload the page
window.location.reload();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment