If user switches tab in the browser, and comes back to the application tab I want to alert the user. I have written following code:
$(function () {
$(window).focus(function () { alert("hi") });
});
The above code runs fine when user gets focus in his application tab, but when I tried to click on OK button of alert box, it again calls the focus event. So jQuery considers messagebox as a different tab other than the current tab, and alert is getting called again and again.
How to call alert only once when user gets focus on tab?