PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → [WB20] How to trap when a user closes or leaves a page
[WB20] How to trap when a user closes or leaves a page
Iniciado por guest, 24,mar. 2016 01:44 - 2 respuestas
Publicado el 24,marzo 2016 - 01:44
Hello All:
I'm using WebDev 20, and I need to do a small processing before the user closes or leaves the current page. I tried putting that process in the Closing of PAGE_Test event, but it seems this is not always triggered... I think if user clicks on a button that opens another page, then this event doesn't happen (I'm not sure if this is exactly the case, but for sure this event not always happens...).

Is there any other way to accomplish this task?

Thanks in advance for your help.

Regards;
Michael R.
Publicado el 24,marzo 2016 - 09:37
Hi Michael,

You have to implement the onbeforeunload event.

In your PAGE or PAGE Template you have to link the event

LOAD (onload) of PAGE_Test (BROWSER) // Set BeforeUnLoad event JSEvent(B_BeforeUnloadPage,jsEventWindow,"beforeunload")
The B_BeforeUnloadPage is also a browser function of that page/Template that will handle the event. I have implemented this on my Template, so all pages based on this template have this functionality.

PROCEDURE B_BeforeUnloadPage(pclEventJS is object dynamic) // if a modification was made IF AJAXExecute(IsPageModified) THEN sMessage is string = "Opgelet, uw aanpassingen zullen verloren gaan wanneer u de pagina verlaat zonder de gegevens op te slaan !" pclEventJS:returnValue = sMessage RESULT sMessage END
Ofcourse you have to handle the code in this last routine.

In my case, if you try to close or browse away from the page when the page was modified (user changed something but did not save) the IsPageModified flag is true and the message will be displayed.
[attachment 1897 screen1.png]

Depending on your selection, you stay on the samepage or you continue to close or goto the other page.

Good luck !
Danny
Publicado el 25,marzo 2016 - 20:28
Hello Danny:

Thanks for the help. I will give it a try and see how it goes.

Many thanks again.
Regards;
Michael