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>
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP