Is there a way that when I click on my browser, and give it focus, to run a method once? And then when the browser loses focus and then gets the focus back to again run that method only once, again.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can attach
focusandblurevent handlers on thewindowobject to track if the window gets or loses focus (see http://jsfiddle.net/whQFz/ for a trivial example).windowapplies to the current browser context (so that could be a window, a tab, a frame, etc.).Note : The
focusevent will fire every time the window gets focus and theblurevent will fire every time it loses focus. An example of something that takes focus away from the window is analertwindow. If you try to alert in anonfocusevent handler you’ll get an infinite loop of alerts!