Thomas Hunter II Thomas Hunter II - 2 years ago 87
Javascript Question

How do I track router change events in Backbone.js

I need to run a function every time the application switches URLs in Backbone.js, and I need to know the hashtag the URL has changed to. I'm assuming there is an event that I can bind to but I haven't been able to figure out which event and what object to bind to.

Specifically I want to ship the new URL to an analytics application.

Answer Source

@qwertymk was half way there. You can look for the hashchange event on the window object:

// jQuery example
$(window).bind('hashchange', function(){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download