HTML事件属性onbeforeunload

2018-01-05 13:58 更新

HTML事件属性onbeforeunload


触发 onbeforeunload 事件在HTML文档被卸载之前。

我们可以使用此事件显示一条消息通知用户离开。

确认对话框中显示默认消息。您不能覆盖此消息。

如果需要,我们可以添加我们自己的消息。

HTML5中的新功能

没有。

句法

<element onbeforeunload="script or javascript function name">

支持的标签

<body>

浏览器兼容性

onbeforeunload Yes Yes Yes Yes Yes


例子

<!DOCTYPE html>
<html>
<body onbeforeunload="return myFunction()">

<a href="http://www.www.w3cschool.cn">Click here to see the dialog.</a>
      
<script>
function myFunction() {
    return "hi";
}
</script>

</body>
</html>

Click to view the demo



以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号