onHashChange: native Javascript function works well, but!
<p>I found this peace of code some where on the web.
I tried it and it works fine:</p>

<pre><code>var onHashChange = function(event) {

    //get hash function
    var getHashValue = function() {

        var arr = window.location.hash.split("#");

        var hasValue = arr[1];

        //sets default
        if (typeof hasValue == "undefined") {
            return false;
        }

        var hashLen = hasValue.indexOf("?");
        if(hashLen&gt;0){
            hasValue = hasValue.substring(0,hashLen);
        }
        return hasValue;

    }

    //last hash
    var lastHash = getHashValue();

    //checker
    (function watchHash() {
        var hash = getHashValue();

        if (hash !== lastHash) {
            event();
            lastHash = hash;
        }

        var t = setTimeout(watchHash, 100);

    })();

} 
</code></pre>

<p>BUT when the function that would be called in the <code>onHashChange</code> many time, it will be repeated for ever.</p>

<pre><code>onHashChange(function() {
  console.log("changed"); 
});
</code></pre>

<p>when am at the same page and the <code>hash</code> is being changed, the <code>console.log</code> will be full of "changed" text even when I made only 3 changes for the hash in the page!</p>

<p>Well, am calling a function "instead of console.log" that at the same time will callback <code>onHashChange</code> again</p>

<p>Any trick to get over it? </p>

<p>Thanks :)</p>
