当HTML文档即将被卸载时执行脚本?

当文档准备卸载时,onbeforeunload 事件属性会触发。

示例

您可以尝试运行以下代码来实现 onbeforeunload 属性 −

<!DOCTYPE html>
<html>
   <body onbeforeunload = return display()>
      <p>Close this window or press F5.</p>
      <script>
         function display() {
            return Wanna stay here or leave?;
         }
      </script>
   </body>
</html>

以上就是当HTML文档即将被卸载时执行脚本?的详细内容,更多请关注双恒网络其它相关文章!

简简单单挺好的

联系我们 订单查询