Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Google Custom Search Engines use a timer to check the hash against a previous value, whilst the child iframe on a seperate domain updates the parent's location hash to contain the size of the iframe document's body. When the timer catches the change, the parent can resize the iframe to match that of the body so that scrollbars aren't displayed.</p> <p>Something like the following achieves the same:</p> <pre><code>var storedHash = window.location.hash; window.setInterval(function () { if (window.location.hash != storedHash) { storedHash = window.location.hash; hashChanged(storedHash); } }, 100); // Google uses 100ms intervals I think, might be lower </code></pre> <p>Google Chrome 5, Safari 5, <a href="http://twitter.com/dstorey/status/15102284544" rel="noreferrer">Opera 10.60</a>, <a href="https://developer.mozilla.org/en/DOM/window.onhashchange" rel="noreferrer">Firefox 3.6</a> and <a href="http://msdn.microsoft.com/en-us/library/cc288209(VS.85).aspx" rel="noreferrer">Internet Explorer 8</a> <strong>all</strong> support the <code>hashchange</code> event:</p> <pre><code>if ("onhashchange" in window) // does the browser support the hashchange event? window.onhashchange = function () { hashChanged(window.location.hash); } </code></pre> <p>and putting it together:</p> <pre><code>if ("onhashchange" in window) { // event supported? window.onhashchange = function () { hashChanged(window.location.hash); } } else { // event not supported: var storedHash = window.location.hash; window.setInterval(function () { if (window.location.hash != storedHash) { storedHash = window.location.hash; hashChanged(storedHash); } }, 100); } </code></pre> <p>jQuery also has a plugin that will check for the hashchange event and provide its own if necessary - <a href="http://benalman.com/projects/jquery-hashchange-plugin/" rel="noreferrer">http://benalman.com/projects/jquery-hashchange-plugin/</a>.</p> <p><strong>EDIT</strong>: Updated browser support (again).</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