Skip to content

Instantly share code, notes, and snippets.

@muodov
Last active February 24, 2022 17:42
Show Gist options
  • Save muodov/bd9b6d20eb1d5e9680baedf19c5ca676 to your computer and use it in GitHub Desktop.
Save muodov/bd9b6d20eb1d5e9680baedf19c5ca676 to your computer and use it in GitHub Desktop.
Location and links behaviour when setting empty hash
Command (executed in this order) Chrome 72 Firefox 65 Safari 12.0.3 IE11
window.location.hash "" "" "" ""
window.location.href "https://example.com/" "http://example.com/" "http://example.com/" "http://example.com/"
window.location.hash = '#' "#" "#" "#" "#"
window.location.href "https://example.com/" "http://example.com/#" "http://example.com/" "http://example.com/#"
window.location.hash "" "" "" "#"
window.location.hash = '#1' "#1" "#1" "#1" "#1"
window.location.href "https://example.com/#1" "http://example.com/#1" "http://example.com/#1" "http://example.com/#1"
window.location.hash "#1" "#1" "#1" "#1"
a = document.createElement('a') <a></a> <a> <a></a> <a></a>
a.href = 'https://example.com' "https://example.com" "https://example.com" "https://example.com" "https://example.com"
a.hash "" "" "" ""
a.href "https://example.com/" "https://example.com/" "https://example.com/" "https://example.com/"
a.hash = '#' "#" "#" "#" "#"
a.href "https://example.com/" "https://example.com/# "https://example.com/" "https://example.com/#"
a.hash "" "" "" ""
a.hash = '#1' "#1" "#1" "#1" "#1"
a.href "https://example.com/#1" "https://example.com/#1" "https://example.com/#1" "https://example.com/#1"
a.hash "#1" "#1" "#1" "#1"
@muodov
Copy link
Author

muodov commented Mar 8, 2019

  1. values returned from the assignment are not the effective ones
  2. .href value after setting an empty hash is browser-specific
  3. It seems as though HTMLAnchorElement and Location might share the same implementation in all browsers except IE

@muodov
Copy link
Author

muodov commented Mar 8, 2019

Also, location = location.href triggers a reload, but location = location.href + "#" doesn't

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