I finally managed to reach a solution which fits my case. I added the following line of code to my .js file.
$(window).bind('hashchange', fooBar);
This way, everytime the URL of the page changes, the function
fooBar
is called. This event is only triggered after the page's DOM is completely loaded.