Created
November 2, 2022 10:25
-
-
Save jarodium/c18289fe84768752b1ead43c0bce677e to your computer and use it in GitHub Desktop.
Remove hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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