Wisej v 3.17 .NetFramework app
I want to detect whenever a user closes the browser or a tab.
if they are editing a record when they close the browser or tab, I need
to detect that and message them to confirm they want to abandon their editing.
I think this concept is called “Intention to close”???
That’s when you go to close and a website will show a popup with an offer
of some sort.. last minute sales pitch etc…
If they confirm, let them close, delete user from loggedin table and
add a record to the loginout table then close the app.
If not editing , just delete user from loggedin table and
add record to the loginout table and close app.
I have sparred with ChatGPT, CoPilot and GitHub AI’s but all kept feeding
me Net Core code. It looks like this is doable but I’m missing something.
Another resource you should consider using is the AI search feature on our website: https://wisej.com/blog/your-wisej-net-questions-answered-powered-by-ai/
For example, if I search “How to prevent the user from closing the browser” I get this result:
You cannot fully prevent a user from closing their browser or tab, but you can warn them before they leave the page using the browser’s built-in “beforeunload” event.
To show a warning when a user tries to close the tab or browser:
window.addEventListener('beforeunload', function (e) { e.preventDefault(); e.returnValue = ''; });
This triggers a confirmation dialog when the user tries to close the tab, refresh, or navigate away. Modern browsers do not allow you to customize the dialog text for security reasons. Users can still choose to leave, so this only acts as a warning, not a true prevention.There is no way to completely block a user from closing their browser or tab, as this would be a security and usability risk. Use the “beforeunload” event to warn users, but always design your application to handle unexpected exits gracefully.
Here you should use the Application.EnableUnloadConfirmation, see documentation here: https://docs.wisej.com/api/v3.5/wisej.web/general/application#enableunloadconfirmation Simply set Application.EnableUnloadConfirmation = true;
See also this forum thread: https://wisej.com/support/question/how-can-i-implement-a-notification-or-warning-message-in-wisej-when-a-user-attempts-to-close-the-browser-or-tab
Please login first to submit.