I am working on mobile browser about 3 months and now i have a boring problem with beforeunload
and onload
. In two situation they do not work clearly. When I close the tab, the browser often calls them. But while user closes the browser with some routine why doesn't it trigger these events at all? What is the problem?
"Many developers treat the unload event as a guaranteed callback and use it as an end-of-session signal to save state and send analytics data, but doing this is extremely unreliable, especially on mobile! The unload event does not fire in many typical unload situations, including closing a tab from the tab switcher on mobile or closing the browser app from the app switcher.
For this reason, it's always better to rely on the visibilitychange event to determine when a session ends, and consider the hidden state the last reliable time to save app and user data."
source: Page Lifecycle API
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With