Created
March 2, 2018 20:21
-
-
Save ekwoster/258c7d12ba690db3c26ba3c8f5e2bb28 to your computer and use it in GitHub Desktop.
Remove hash with # from window.location.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 unhash () { | |
var sy, sx; | |
if ("pushState" in history) | |
history.pushState( | |
"", document.title, | |
window.location.pathname + window.location.search | |
); | |
else { | |
// сохраняем позицию прокрутки страницы в переменные | |
sy = document.body.scrollTop; | |
sx = document.body.scrollLeft; | |
window.location.hash = ""; | |
// восстанавливаем позицию, если страница прокрутилась | |
document.body.scrollTop = sy; | |
document.body.scrollLeft = sx; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment