0

Problem is (at least with my current browser), changing the hash tag and entering the new url doesn't trigger a refresh of the page, and thus I'm not aware offhand how to detect when this hash tag change has been made.

Is there an elegant way to do this?

Hamster
  • 2,962
  • 7
  • 27
  • 38

2 Answers2

1

Check for a new location.hash

mVChr
  • 49,587
  • 11
  • 107
  • 104
0

This is a nasty-ish solution, but you can poll the URL for a change every so often:

var hash = window.location.hash;

function poll() {
  if (window.location.hash != hash) {
    hash = window.location.hash;

    // Hash has changed. Do stuff here.
  }
}

setInterval(poll, 100);
Blender
  • 289,723
  • 53
  • 439
  • 496