卸载(或刷新)页面时触发卸载事件。您可以尝试运行以下代码来了解如何在 JavaScript 中实现 onunload 事件。
<!DOCTYPE html> <html> <body onunload="newFunc()"> <p>Close the page and see what happens!</p> <p>This event may give unexpected results.</p> <script> function newFunc() { alert("Thank you!"); } </script> </body> </html>