onbeforeunload 事件在 JavaScript 中的用法是什麼?
如果您希望在文件載入之前觸發某個事件,那麼請使用 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>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP