要在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>热门推荐
10 贺卡文字同事祝福语简短
11 道教生日祝福语简短大全
12 给儿子祝福语简短霸气
13 2026猪年祝福语简短语
14 叔叔生日祝福语简短搞笑
15 小朋友祝福语简短的话
16 要过年了祝福语简短
17 剪简短的新年祝福语
18 前程祝福语简短暖心