
当文档准备卸载时,onbeforeunload 事件属性会触发。
示例
您可以尝试运行以下代码来实现 onbeforeunload 属性 −
1 2 3 4 5 6 7 8 9 10 11 | <!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>
|
登录后复制
以上是当HTML文档即将被卸载时执行脚本?的详细内容。更多信息请关注PHP中文网其他相关文章!