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="http://code.jquery.com/jquery-1.12.4.min.js"></script> <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'); clearInterval(interval_id); interval_id = 0; }); </script>