recently, I had the urgent requirement to give my server a notice, that a specific page of my webapp is about to get closed. \"Easy peasy\" I thought, beforeu
The thing to keep in mind is that beforeunload
started as an extension by Internet Explorer. Automatically, that makes it a second-class citizen on the web. There is no specification, and browser implementation varies. For example, Firefox only partially implements it by not displaying the string, only a generic message.
Additionally, even when fully implemented, it does not protect against all possible unload scenarios, eg, the user has terminated the processor, the browser has crashed, or the computer has been turned off. Even ignoring these extreme scenarios, I suspect that it might be possible to configure your browser to ignore such requests.
My feeling is that you shouldn't rely on this message to save you. If this web app is internal, I would suggest training them to use the Save
or Close
or whatever buttons instead of just closing the tab. If it's external, maybe look into automatic saving as the user does their thing?