Team:UNITN-Trento/JS/Library/onHashChange

From 2013.igem.org

/**

* onHashChange (oHch) event handler
* @version onHashChange 1.0
* @copyright Copyright (c) 2010-2012, Gabriele Girelli
* @author ggirelli <g.girelli@studenti.unitn.it>
*/

function oHch(event) {

   var getHashValue = function() {
       var hasValue = window.location.hash.split("#")[1];
       if (typeof hasValue == "undefined") {
           return false;
       }
       return hasValue;
   }

var lastHash = getHashValue();

   (function listenHash() {
       var hash = getHashValue();
       if (hash !== lastHash) {
           event();
           lastHash = hash;
       }
       var t = setTimeout(listenHash, 100);
   })();

}