代码示例:(标识:event_onbeforeunload)
<!DOCTYPE html>
<html>
<body onbeforeunload="return myFunction()">

<p>请重新加载此页面,或单击下面的链接以调用 onbeforeunload 事件。</p>

<a href="https://www.sou-xun.com">点击此处访问 sou-xun.com</a>
    
<script>
function myFunction() {
  return "Write something clever here...";
}
</script>

</body>
</html>
运行结果: