首頁  >  文章  >  web前端  >  在JavaScript中,onbeforeunload事件的用途是什麼?

在JavaScript中,onbeforeunload事件的用途是什麼?

PHPz
PHPz轉載
2023-09-02 18:33:021050瀏覽

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

以上是在JavaScript中,onbeforeunload事件的用途是什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除