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

  1. no hash
  2. just hash
  3. hash text

however seems js doesn't see difference between example.com/ , example.com/# can't figure out how remove hash completely.

any help?

  1. once hash set, cannot remove altogether (eg, remove # sign) without causing page reload; normal behavior.

  2. 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

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -

PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea -