Skip to content

Instantly share code, notes, and snippets.

@jarodium
Created November 2, 2022 10:25
Show Gist options
  • Save jarodium/c18289fe84768752b1ead43c0bce677e to your computer and use it in GitHub Desktop.
Save jarodium/c18289fe84768752b1ead43c0bce677e to your computer and use it in GitHub Desktop.
Remove hash
function removeHash () {
var scrollV, scrollH, loc = window.location;
if ("pushState" in history)
history.replaceState("", document.title, loc.pathname + loc.search);
else {
// Prevent scrolling by storing the page's current scroll offset
scrollV = document.body.scrollTop;
scrollH = document.body.scrollLeft;
loc.hash = "";
// Restore the scroll offset, should be flicker free
document.body.scrollTop = scrollV;
document.body.scrollLeft = scrollH;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment