"onbeforeunload" event. The following example explains the idea.
In this example, there is a simple form that contains an input text. When the user enters something in the input text, a warning message appears.
"onbeforeunload" event is called when the user tries to leave the page. As shown in the code, to display the interruption message
"You entered information in the page. Are you sure you want to leave now?", you have to specify the interruption message in the return of the event. The interruption message is displayed as shown in the figure below.
This code works with me on IE, Firefox, and Safari. I wish that this tip can be useful for you.