Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$(window).hashchange() doesn't work

Hi,

I'm trying to use the browser back button, i understood how to catch the event with hashchange plugin =>

$(window).hashchange( function(){
    alert( location.hash );
});$(window).hashchange();

When i try to load the new page, nothing happens.. Is there a way to "reload" the page with the new url ?

Thanks !

like image 450
Thomas Saldi Avatar asked May 15 '12 08:05

Thomas Saldi


2 Answers

Try this instead:

$(window).on('hashchange', function(){
    // Your code goes here
}).trigger('hashchange'); // bind event to the same selector as event-listener

.trigger() basicly activates events manually.

EDIT:
This should be enough for you to work.

Try this piece of code and see if you got any luck.

Included javascript.js is compressed with jquery and hashchange.

like image 127
Robin Castlin Avatar answered Oct 23 '22 20:10

Robin Castlin


Put $(window).bind('hashchange', function() {}); outside of the document.ready

like image 42
Jasper Giscombe Avatar answered Oct 23 '22 19:10

Jasper Giscombe