<code class="language-text">var lastFired = new Date().getTime();
setInterval(function() {
now = new Date().getTime();
if(now - lastFired > 5000) { // if it's been more than 5 seconds
alert("onfocus");
}
lastFired = now;
}, 500);
</code>