Alex Rivera | Logout

Handle URL fragment identifier (anchor) change event in Javascript

Asked 2010-01-29T12:39:15.717
101

How can I write the Javascript callback code that will be executed on any changes in the URL fragment identifier (anchor)?

For example from http://example.com#a to http://example.com#b

Edit
Report

2 Answers

3

From what I see in other SO questions, the only workable cross-browser solution is a timer. Check out this question for example.

answered 2010-01-29T12:41:47.147
2

(Just for the record.) The YUI3 "hashchange" synthetic event does more or less the same thing as the accepted answer

YUI().use('history-hash', function (Y) {
  Y.on('hashchange', function (e) {
    // Handle hashchange events on the current window.
  }, Y.config.win);
});
answered 2011-07-08T20:32:11.330

Your Answer