<html>
<body onbeforeunload="return myFunction()">
<h1>HTML DOM Events</h1>
<h2>The beforeunload Event</h2>
<p>This example assigns an "onbeforeunload" event to a body element.</p>
<p>Close this window, press F5 or click on the link below to invoke the onbeforeunload event.</p>
<a href="https://www.w3schools.com">Click here to go to w3schools.com</a>
<script>
function myFunction() {
return "Write something clever here...";
}
</script>
</body>
</html>