JavaScript 中 onbeforeunload 事件有什麼用?


如果要在文件載入之前觸發事件,可以使用onbeforeunload事件。

示例

你可以嘗試執行以下程式碼來學習如何在 JavaScript 中實現 onbeforeunload 事件。

<!DOCTYPE html>
<html>
   <body onbeforeunload="return myFunction()">

      <a href="https://www.qries.com">Click to open Qries</a>
      <script>
         function myFunction() {
            return "Working with onbeforeunload event";
         }
      </script>
   </body>
</html>

更新於: 21-5-2020

124 次瀏覽

開啟你的 事業

完成課程即可獲得認證

開始
廣告
© . All rights reserved.