在 HTML 中为页面卸载时执行脚本?


unloaded 属性会在网页卸载时触发。你可以尝试运行以下代码在 HTML 中实现 unloaded 属性 −

示例

<!DOCTYPE html>
<html>
   <body onunload = "display()">

      <h2>Tutorialspoint</h2>
      <h3>Simply Easy learning</h3>

      <script>
         function display() {
            alert("Bye!");
         }
      </script>

   </body>
</html>

更新于: 2020 年 03 月 03 日

110 人查看

开启你的 职业生涯

通过完成课程获取认证

开始
广告