var hashWatch = (function (api){
var interval = setInterval,
oldHash = location.hash+'';
var api = api || {};
api.event = new CustomEvent("hashchange", { "detail": "Ativado quando há uma mudança no location.hash" });
api.detect = function(){
if(oldHash != location.hash){
oldHash = location.hash+'';
document.dispatchEvent(api.event);
}
}
api.startWatch = function(){
interval = setInterval(api.detect,100);
}
api.stopInterval = function(){
clearInterval(interval);
}
api.startWatch();
return api;
})(hashWatch);
window.addEventListener('hashchange', function(){
console.log(location.hash);
},true)
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.