<!DOCTYPE html>
<html lang="en-US">
<body onunload="myFunction()">
<p>onunload will trigger when you close/ refresh this window.</p>
<p>Click on 'Run' button and check your console (Press F12)</p>
<script>
function myFunction(){
console.log("This page is unloaded");
}
</script> </body>
</html>