the problem is that I am making a program, such as a chat, which should know if the user has left the window or switched to another window or tab so that other users can see what the other user is not seeing now.
I thought that the focal event of the window would solve my problems, however there are a few problems with it. First: it does not fire only when the user leaves the window, if they focus on the input field, and then click elsewhere on the page, the event fires. Obviously, this is unbearable. In Firefox, I managed to get around this. In Firefox, when this happens, the browser fires a focus event once. If you really leave the window, it fires twice. So, a little programming did the magic.
Then the second problem appeared: Chrome, and I believe that another browser can behave the same way, only fires a focus event once, no matter what you do. Leaving the window, changing the focus from the inputs to the page, is the same, so my programming did not work there.
Does anyone know a way to mimic the desired behavior? Or a way to make Chrome and other possible browsers behave like Firefox or something else?
Thanks everyone!
source
share