Team:UNITN-Trento/JS/Library/onHashChange

From 2013.igem.org

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

Latest revision as of 16:36, 8 August 2013

/**

* 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);
   })();

}