Hello everyone!
I'm trying to throw a confirmation message when the user clicks to close the browser page(the tab). How can I achieve that?
I've tried this, but without success:
This javascript doesn't work and I don't know why... I hope you can help me! Thanks in advance.
Hi Daniel,
Did you check the console for any errors?
EDIT: Did you check this page? The code shown there is a bit more extensive.
Kilian Hekhuis wrote:
Hi Killian, I used the code provided by this page. It really worked, thank you so much!
But I have a challenge. I have a button at my page, called "Read Confirmation". This button is used by the users to confirm if the news was read. So, the challenge is to throw a confirmation message whenever the user tries to leave the page without press the "Read Confirmation" button. So, I guess I'll need a variable to store if the user clicked on the button or not...
Do you have any idea how can I integrate this with the JS code that I already have? Thanks in advance!
Daniel Almeida wrote:
Hi Daniel, this is traditional or reactive? do you have a theme associated with the app? witch one? Are you interacting with the page when trying to close?
Check this sample is the same as yours but I have the theme based in the Dublin theme. check the oml attached
ps:. You need to interact with the page to work
cheers
Carlos Lessa
Carlos Lessa wrote:
Hi Carlos, I'm using Traditional. I have another theme module being consumed by this one. I have a challenge...
I have a button at my page, called "Read Confirmation". This button is used by the users to confirm if the news was read. So, the challenge is to throw a confirmation message whenever the user tries to leave the page without press the "Read Confirmation" button. So, I guess I'll need a variable to store if the user clicked on the button or not...
Thank you so much for replying!
Hi,
Can I suggest that you create the function and then create the event listener to use that function?
Something like that:
function onBeforeUnload(e) { if (thereAreUnsavedChanges()) { e.preventDefault(); e.returnValue = ''; return; } delete e['returnValue']; } window.addEventListener('beforeunload', onBeforeUnload);
This is just an example.
Best regards,
Ricardo M Pereira
Ricardo Pereira wrote:
Ricardo, I guess this function really works too. Thank you so much for helping me!