<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html">
<title>onbeforeload测试</title>
<script type="text/javascript">
function checkLeave(ev){
ev.returnValue="你确定离开当前的页面吗";
}
</script>
</head>
<body onbeforeunload="checkLeave(event)">
<p>好好学习</p>
</body>
</html>
<!-- onbeforeunload这个事件是在浏览器上关闭这个页面的时候会被调用
我们可以看到调用这个事件的时候对调用一个javaScript的函数,在刷新网页的
时候也会被调用
-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html">
<title>onbeforeload测试</title>
<script type="text/javascript">
function checkLeave(ev){
ev.returnValue="你确定离开当前的页面吗";
}
</script>
</head>
<body onbeforeunload="checkLeave(event)">
<p>好好学习</p>
</body>
</html>
<!-- onbeforeunload这个事件是在浏览器上关闭这个页面的时候会被调用
我们可以看到调用这个事件的时候对调用一个javaScript的函数,在刷新网页的
时候也会被调用
-->
本文展示了如何使用onbeforeunload事件在浏览器关闭当前页面时触发JavaScript函数,实现对用户离开页面的提示,即使在刷新页面时也会被调用。

659

被折叠的 条评论
为什么被折叠?



