<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body onbeforeunload="return leave()">
<div>
hello
</div>
<script>
function leave() {
console.log("禁止离开");
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body onbeforeunload="return leave()">
<div>
hello
</div>
<script>
function leave() {
console.log("禁止离开");
}
</script>
</body>
</html>
本文标题:JS 禁止离开页面或刷新页面
本文链接:https://www.haomeiwen.com/subject/mdxvnqtx.html
网友评论