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

更新於: 03-Mar-2020

126 瀏覽

開啟你的 職業

完成課程認證

立即開始
廣告