Hamster
Hamster

Reputation: 3142

Javascript: Need to detect when a user revisits the page with a changed hash tag

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?

Upvotes: 0

Views: 147

Answers (2)

Blender
Blender

Reputation: 298532

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);

Upvotes: 0

mVChr
mVChr

Reputation: 50205

Check for a new location.hash

Upvotes: 1

Related Questions