在 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.