I'm making an ajax site. How would I go about executing some javascript every time the url changes. Say when "/#page/aboutus/" changes to "/#page/news/".
I want users to be able to bookmark ajax-pages.
I'm making an ajax site. How would I go about executing some javascript every time the url changes. Say when "/#page/aboutus/" changes to "/#page/news/".
I want users to be able to bookmark ajax-pages.
This may be easier to do a different way, for example a .live() event handler:
$("a").live('click', function() {
//do something with this.hash
});
But, if you do indeed need to trigger with location.hash changes, you can use the onhashchange plugin for this (at least until it's supported natively in every browser).
For example:
$(window).bind('hashchange', function(){
//do something with location.hash here
});