javascript - URL Hash oddities -
i've noticed strange behaviour in js
window.location.hash = ''; var hash = window.location.hash; alert(hash + ' = ' + hash.length); //outputs: ' = 0' window.location.hash = '#'; hash = window.location.hash; alert(hash + ' = ' + hash.length); //outputs: ' = 0' window.location.hash = '_'; hash = window.location.hash; alert(hash + ' = ' + hash.length); //outputs: '_ = 2' basically want trigger 3 conditions
- no hash
- just hash
- hash text
however seems js doesn't see difference between example.com/ , example.com/# can't figure out how remove hash completely.
any help?
once hash set, cannot remove altogether (eg, remove
#sign) without causing page reload; normal behavior.setting empty/null hash , setting hash default hash (
#) treated same; internal behavior. not sure if browsers handle consistently, iirc case.
ultimately if want remove hash completely, have document.location.href = document.location.href, reload page (window.location.reload() keep hash).
Comments
Post a Comment