JQuery - tell me when hash changes?

I am trying to make my site the correct answer to the back button. I saved this hash of what I want, but I don't know how to use jQuery to determine when the hash changes. This is not .ready () because the page is not reloading. What am i using?

Edit for clarity:

I use iframe, so I can not say when someone clicks on the link. It is on the same subdomain, so I can see its path to the file, and I save it so you can add bookmarks. Unfortunately, saving it as a hash, my back button no longer reboots, which prevents the iframe from reloading, so my back button is essentially broken. If there was a way to tell when the URI changes, I can check it for the iframe address and change it if they don't match.

All I need to do is check if the URI has changed. Is there a .change () for a URI? Something like that?

+1
javascript jquery fragment-identifier
Sep 02 '09 at 18:02
source share
5 answers

After the document is ready, you will examine the hash and modify the page accordingly.

I don't know which hook for jQuery can I say when the hash changes

You can capture the events of hash anchor clicks and react accordingly, rather than waiting for the "hash has changed" event (which does not exist).

Some approaches generate a “hash changed” event by checking window.location.hash for a timer.

+3
Sep 02 '09 at 18:07
source share

You can try the Event History Plugin .

+4
Sep 02 '09 at 18:07
source share

Ben 'cowboy' Alman wrote a cross-platform plugin for hash changes

http://benalman.com/news/2010/07/jquery-hashchange-event-v13/

I don’t know if you use it inside an iframe or what, but if you used it outside the iframe, it would be like

 $(function(){ $(window).hashchange(function(){ //Insert event to be triggered on has change. changeIframeContent(window.location.hash); }) }) 
+2
Jan 18 2018-11-11T00:
source share

You should take a look at the Ben Nadel solution , which binds events to objects other than the DOM.

+1
Oct 24 '09 at 11:24
source share

There is a buitin method for tracking hash changes, in firefox you can use the watch method, but as far as I know, this is not the default, so you can hack it to something like that (see below)

 function setWatchHashChanges(functionObject) { if(window.location.watch) { window.location.watch('hash', function(e){functionObject(e);return e;}); } else { if(!setWatchHasnChanges.hash) { setWatchHasnChanges.hash = window.locaton.hash; } else { setInterval(function(){ if(setWatchHasnChanges.hash!== window.locaton.hash) { setWatchHasnChanges.hash = window.locaton.hash; functionObject(setWatchHasnChanges.hash); } }, 100); } } 
0
Sep 02 '09 at 18:23
source share



All Articles