Catch closing of browser or that the user moves to another page

I’m trying to find a way to warn the user that he is about to leave the web-app, either by closing the browser, by clicking Back or by entering a new URL.

I have tried different solutions using WebApplication.Close and WebSession.Close, but I can’t figure out how to do it.

Do any of you smart guys have a solution to this?

See https://documentation.xojo.com/index.php/WebSession.ConfirmMessage

In pure JavaScript, the event you cant to catch is Window: beforeunload event - Web APIs | MDN

Thank you Michael. If I understand this correctly:

  1. Xojo can display a message when you are leaving the app, but the app cannot prevent the user from leaving the app.

  2. If I’m able to catch (and handle) the JavaScript event BeforeUnload, I will be able to let the user stay in the app

Does anyone know how catch and handle BeforeUnload?

Try the ConfirmMessage route first. It’s built in and I believe it’ll do everything the JavaScript route would do for you.

Thank you Greg, that worked fine.