Confirmation before Exit

On most pages, if you perform an action (such as editing, creating), and when I try to exit, it basically tells me if I really want to exit. The dialog gives me two options: leave or cancel and continue. How do you do this in javascript? Should I use a meta element? And please do not mention beforeunload unless this is the true and only way to accomplish this.

+9
source share
3 answers

Why not mention onbeforeunload ? This is a built-in way to do this, and I see no problem using it.

 function myConfirmation() { return 'Are you sure you want to quit?'; } window.onbeforeunload = myConfirmation; 
+18
source

what i use is:

 onClick="return confirm('Sure you want to exit..?')" 
0
source
 window.onbeforeunload = function() { if(confirm('are you sure to exit?')) return true; else return false; }; 
-5
source

Source: https://habr.com/ru/post/947440/


All Articles