Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The only way to really do this (and is how the 'reallysimplehistory' does this), is by setting an interval that keeps checking the current hash, and comparing it against what it was before, we do this and let subscribers subscribe to a changed event that we fire if the hash changes.. its not perfect but browsers really don't support this event natively.</p> <hr> <p>Update to keep this answer fresh:</p> <p>If you are using jQuery (which today should be somewhat foundational for most) then a nice solution is to use the abstraction that jQuery gives you by using its events system to listen to hashchange events on the window object.</p> <pre><code>$(window).on('hashchange', function() { //.. work .. }); </code></pre> <p>The nice thing here is you can write code that doesn't need to even worry about hashchange support, however you DO need to do some magic, in form of a somewhat lesser known jQuery feature <a href="http://benalman.com/news/2010/03/jquery-special-events/" rel="noreferrer">jQuery special events</a>.</p> <p>With this feature you essentially get to run some setup code for any event, the first time somebody attempts to use the event in any way (such as binding to the event).</p> <p>In this setup code you can check for native browser support and if the browser doesn't natively implement this, you can setup a single timer to poll for changes, and trigger the jQuery event.</p> <p>This completely unbinds your code from needing to understand this support problem, the implementation of a special event of this kind is trivial (to get a simple 98% working version), but why do that <a href="http://benalman.com/projects/jquery-hashchange-plugin/" rel="noreferrer">when somebody else has already</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload