0
jquery or javaScript window close event
I want to update online status to false on MySQL. before close window. How can i?
5 Antworten
+ 5
Prafull Epili I recommed reviewing the various events and developer recommendations on this link:
https://developers.google.com/web/updates/2018/07/page-lifecycle-api
+ 4
Prafull Epili You can try sendBeacon() with onbeforeunload or PageLifecycle.js when closing from most browsers, except IE.
Chromium based browsers will ignore any attempt to send synchronous XHR requests during the unload or beforeonload events.
Just be aware that sendBeacon() is asynchronous and does not wait for any acknowledgement responses. So... delivery cannot be guaranteed by the server with sendBeacon().
Since I'm unable to save links for some reason, I've posted reference links in this code:
https://code.sololearn.com/c9cp73JBO4Sf/?ref=app
+ 2
when users makes requests, you store their timedate.
when you need the information about online status of a specific user, you compare the actual timedate to the stored timedate of last user request: if less than a limit you define (ie 5 min), the user is 'active/online' else he's not...
+ 1
You rather need to handle online status by other ways...
First, the moment where user close window is too late to do a server request.
Second, what for unclosed window/tab but no more focused by user?
Usually, online auto status update are done by detecting no activities (no request) from specific user on server side since few minutes (say 5)...
0
visph How to catch no activity(no request) from user if I use using Ajax. Please reply..