I would like to know that the user is leaving the web page. I think there can be three scenarios: 1. go to another page on the same website, or open a new window, or load a new page in the current window, 2. go to a page on another site and 3. close the window.
Based on these scenarios, I think I need to check if the current window is the focus. So my first question is: is this correct? And the second question: how do I implement it in javascript?
source
share