How to show a warning message when closing a window?

Possible duplicate:
How to prevent browser window from closing?

I want to show the warning message β€œPlease log out before closing the window” with the exit button when the user tries to close the window and after clicking the exit button the window may be closed. How to achieve this?

+4
source share
3 answers

Another implementation you can try:

<html> <head> <script type="text/javascript"> window.onbeforeunload = function() { return "Did you save your stuff?" } </script> </head> <body> </body> </html> 
+8
source
 window.onbeforeunload = function() { return "Are you sure?"; }; 

Try it.

+2
source

There is no such closed event in Javascript. You can pass onUnload message. But this does not prevent the application from closing. This function will be executed when the user clicks any link, submits a form, etc.

 window.onunload=function(){SomeJavaScriptCode}; 

For reference: http://www.w3schools.com/jsref/event_onunload.asp

+1
source

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


All Articles