Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove prompt on unload event using javascript

How can I remove prompt on unload event using javascript? thanks in advance...

hm, I don't want to show the prompt when firing the custom function for the unlaod event of the body... Is it possible? so here's my code:

window.onbeforeunload = function()
{
    //cancel the unload
            //cancel prompt
}
like image 696
dpp Avatar asked Jul 13 '26 00:07

dpp


1 Answers

Make sure your event handler doesn't have a return statement in it. Returning from the function triggers the conformation message.

Update based on the code comments in the edited question: If the user does something to leave the page, then you can tell the browser to ask them if they are sure. You cannot silently prevent them. If the user wishes to leave the page, then they can do so (dodgy sites full of adverts and/or malware would love it to be otherwise, thankfully it isn't)

like image 79
Quentin Avatar answered Jul 15 '26 13:07

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!