"离开此页"效果

<html>
<head>
<script type="text/javascript">
var dont_confirm_leave = 0; //set dont_confirm_leave to 1 when you want the user to be able to leave withou confirmation
var leave_message = '确实要关闭吗?'
function goodbye(e) {
if (dont_confirm_leave !== 1) {
if (!e)
e = window.event;
e.cancelBubble = true;
e.returnValue = leave_message;
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
//return works for Chrome and Safari
return leave_message;
}
}
window.onbeforeunload = goodbye;
</script>
</head>
<body>
<b>dsdsf</b>
</body>
</html>

你可能感兴趣的:(JavaScript,html,chrome,Safari)