0

jquery or javaScript window close event

I want to update online status to false on MySQL. before close window. How can i?

1st Jan 2021, 8:37 PM
Prafull Epili
Prafull Epili - avatar
5 Respostas
+ 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
2nd Jan 2021, 6:34 AM
David Carroll
David Carroll - avatar
+ 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
1st Jan 2021, 9:55 PM
David Carroll
David Carroll - avatar
+ 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...
2nd Jan 2021, 6:20 AM
visph
visph - avatar
+ 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)...
1st Jan 2021, 8:50 PM
visph
visph - avatar
0
visph How to catch no activity(no request) from user if I use using Ajax. Please reply..
2nd Jan 2021, 6:13 AM
Prafull Epili
Prafull Epili - avatar