在 HTML 中,当浏览器窗口关闭时执行脚本?


当你关闭 Web 浏览器窗口时,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年3月3日

579 次浏览

开启你的 职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.