1

Hey everyone, this code is meant to read what comes after the hash in the url and display a specific div depending on that value. Right now it works fine, except for when you try changing the hash while you're already on the site (or if you hit the back button, which has the same effect: changes the hash, but the div isnt changed). The site is made so that it doesnt reload with every div change (the main content of the page), so I'm assuming the reason the div doesnt change when you hit the back button or type in a different value after the hash is because the page is already loaded, and the javascript code is only called once on page load. I need a way for it to be called whenever the url is changed. Here's the code:

function hash() { var hash = window.location.hash.replace('#',''); InsertContent(hash); }

pobrien
  • 63
  • 1
  • 4

3 Answers3

0

I'm afraid it's not a bug, it's a feature. Opera for example stores the exact state of a page in memory. So if you hit the back button, that state will be restored exactly. It's like you've never change the page.

Changing the hash should work though, by calling InsertContent() right after you've changed the hash. Doesn't that work? Can you show us the code?

DanMan
  • 11,323
  • 4
  • 40
  • 61
0

You need to poll the window.location.hash and see if it changes. Some browsers support onhashchange event.

Another discussion: On - window.location.hash - Change?

Community
  • 1
  • 1
epascarello
  • 204,599
  • 20
  • 195
  • 236
0

jQuery has a plugin called "address" to address this problem

Michael Lorton
  • 43,060
  • 26
  • 103
  • 144