The onbeforeunload
event is triggered
before the HTML document is unloaded.
We can use this event display a message to inform the user of leaving.
There is a default message appearing in the confirmation dialog. You cannot overwrite this message.
We can add our own message if necessary.
None.
<element onbeforeunload="script or javascript function name">
<body>
onbeforeunload |
Yes | Yes | Yes | Yes | Yes |
<!DOCTYPE html>
<html>
<body onbeforeunload="return myFunction()">
<!--from w w w . jav a 2 s. c o m-->
<a href="http://www.java2s.com">Click here to see the dialog.</a>
<script>
function myFunction() {
return "hi";
}
</script>
</body>
</html>