Alternative to jQuery ready() for detecting that the page anchor in the URL changes
<p>Does anyone know how to get a page load event to fire if the page anchor in the URL changes, i.e., going from </p>

<pre><code>http://mywebsite.com/#test1  
to 
http://mywebsite.com/#test2
</code></pre>

<p>when using the Back button?</p>

<p>I tried the code at the bottom (the <code>history.navigationMode</code> line along with the <code>ready()</code> function insures that the onload event fires even when the browsers Back button is used), but it doesn't work if only the page anchor portion of the URL changes and the Back button is used.  I know this code works if the URL changes it's query string (or the URL points to a new file/folder) because I use this all the time but it looks like jQuery's ready() function doesn't fire when the Back button is used if only the page anchor location in the URL changes.</p>

<p>I'm trying to come up with a solution for making the browser's Back button preserve JavaScript/AJAX manipulations of the page and I'm basing my attempt on this person's idea: <a href="http://www.ajaxonomy.com/2008/web-design/a-better-ajax-back-button-part2" rel="nofollow">http://www.ajaxonomy.com/2008/web-design/a-better-ajax-back-button-part2</a> but without relying on using a repeating timer to check if the URL page anchor has changed - I would rather check this when the page onload event fires.</p>

<p>Any ideas/suggestions? </p>

<pre><code>&lt;script language="javascript" type="text/javascript" src="/jquery.js"&gt;&lt;/script&gt;
&lt;script language="javascript" type="text/javascript"&gt;
history.navigationMode = 'compatible';
$(document).ready( function() {
   if(document.location.hash){
      var hashQueryString = document.location.hash;
      hashQueryString = hashQueryString.replace("#","");
      alert(hashQueryString);
   }
});
</code></pre>
