<html>
<head>
<script>
window.addEventListener("beforeunload", function (event) {
setTimeout(function() {
window.alert("hi");
}, 0);
});
</script>
</head>
<body>
</body>
</html>
<html>
<head>
<script>
window.addEventListener("beforeunload", function (event) {
setTimeout(function() {
window.alert("hi");
}, 0);
});
</script>
</head>
<body>
</body>
</html>