Skip to content

Instantly share code, notes, and snippets.

@sunny
Last active January 18, 2023 12:04
Show Gist options
  • Save sunny/481146 to your computer and use it in GitHub Desktop.
Save sunny/481146 to your computer and use it in GitHub Desktop.
// Change window.location.hash without scrolling the page, even in IE
// by renaming the element's id temporarily
function changeHashWithoutScrolling(hash) {
const id = hash.replace(/^.*#/, '')
const elem = document.getElementById(id)
elem.id = `${id}-tmp`
window.location.hash = hash
elem.id = id
}
@sunny
Copy link
Author

sunny commented Sep 12, 2021

Woops. Thanks for the heads-up, it’s now updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment