<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>onbeforeunload</title>
<!--第一种方法(刷新)-->
<script language="javascript">
window.onbeforeunload = function (e) {
e = e || window.event;// For IE and Firefox prior to version 4
if (e) {
e.returnValue = '页面信息是否保存,确定离开当前页面吗??';
}// For Safari
return '页面信息是否保存,确定离开当前页面吗??';
};
</script>
<!--第二种方法-->
<script type="text/javascript">
window.onbeforeunload = function(e){
if(window.event){
window.event.returnValue = "页面信息是否保存,确定离开当前页面吗";
return false;
}
}
</script>
</head>
<body>
</body>
</html>
针对onbeforeunload事件浏览器兼容方法,支持所有浏览器
最新推荐文章于 2023-11-08 10:40:09 发布
本文介绍了如何使用onbeforeunload事件来提示用户是否离开当前页面,提供了两种实现方式,一种适用于IE和Firefox浏览器,另一种适用于Safari等现代浏览器。
978

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



