Alex Rivera | Logout

How can I trigger on URL change in jQuery?

Asked 2012-09-10T10:35:53.020
25

How can I trigger a function when the URL changes? I try something like:

$(windows.location).change(function(){
   //execute code
});

So my URL is something like http://www.mysite.com/index.html#/page/1. How can I execute jQuery or JavaScript code when the URL becomes something like http://www.mysite.com/index.html#/page/2?

Edit
Report

1 Answer

4

Try the hashchange event, which is built exactly for this - http://benalman.com/projects/jquery-hashchange-plugin/

answered 2012-09-10T10:37:58.667

Your Answer