4

I am using this plugin http://www.asual.com/jquery/address/ for detecting hash changes and such for my website, it only uses this for its navigation so it's a vital part of the users experience. Now this works perfect for everything I am doing with it, except it doesn't trigger the event if the hash doesn't change/isn't different than the last hash url that was clicked, for example if I'm on example.com/home and click the homepage icon again it doesn't reload the page again, like if you are just using regular links it does. I haven't been able to figure out how to achieve this for all links that are part of the url. (not just all tags because I use tags without it being a navigational part. So any help would be great, thanks.

$.address.change(function(event){  
 ///events to be triggered on hash change
});
Matt
  • 22,721
  • 17
  • 71
  • 112
Dylan Cross
  • 5,918
  • 22
  • 77
  • 118

1 Answers1

5

The onhashchange event is aptly named, it only fires when the hash changes.

The only solution that I am aware of for this problem would be to bind the same function to the homepage icon's click event.

Also, jQuery provides it's own event for hash change:

$(window).on("onhashchange", function (e) {
     route();
})
$(".icon").on("click", function(e) {
     location.hash == "#/" ? route(): null;
})

Also, if these are a tags, say, in a #nav div:

$("#nav").delegate("a", "click", function () {
     location.hash == this.href ? route() : null;
})

Or this can just be applied to all a tags:

$("a").on("click", function () {
     location.hash == this.href ? route() : null;
})
Austin
  • 6,026
  • 2
  • 24
  • 24