Trigger JavaScript after set time of window or tab focus

Following code shows how to trigger JavaScript code after a specified time interval when getting back to windows or tab of the browser:

<script src=""></script>

	function callOnFocus() {
		alert('Triggers after one second of window or tab focus!');

	var interval_id;
	$(window).focus(function() {
	    if (!interval_id)
	        interval_id = setInterval(callOnFocus, 1000);

	$(window).blur(function() {
		// alert('On blur test');
	    interval_id = 0;