<body onbeforeunload="myFunction()"> - Javascript DOM Event

Javascript examples for DOM Event:onbeforeunload

Introduction

The onbeforeunload event occurs when the document is about to be unloaded.

Summary

Bubbles No
Cancelable Yes
Supported HTML tags: ?<body>

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body onbeforeunload="return myFunction()">

<a href="https://www.java2s.com">Click here</a>

<script>
function myFunction() {//from w ww.ja  v a  2s . c  o m
    return "Write something clever here...";
}
</script>

</body>
</html>

Related Tutorials