在 HTML 中卸载文档时执行脚本?
onbeforeunload 事件属性在文档准备好被卸载时触发。
示例
你可以尝试运行以下代码来实现 onbeforeunload 属性 −
<!DOCTYPE html>
<html>
<body onbeforeunload = "return display()">
<p>Close this window or press F5.</p>
<script>
function display() {
return "Wanna stay here or leave?";
}
</script>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP