Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yes/No box in Javascript like this one here in StackOverflow?

Tags:

javascript

I want to know how can I display a confirmation box when the users try to get out of the page, like this one here in StackOverflow when you try to close the "Ask Question" page.

Thanks you in advance.

like image 643
Bernardo Amorim Avatar asked May 16 '26 17:05

Bernardo Amorim


1 Answers

Actually, all that is necessary is this:

window.onbeforeunload = function(){ return "You should save your stuff."; }

This is also kind of a dupe of this: How to show the "Are you sure you want to navigate away from this page?" when changes committed?

like image 127
Eric Mickelsen Avatar answered May 19 '26 07:05

Eric Mickelsen



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!