您可以尝试的另一个实现:
<html>
<head>
<script type="text/javascript">
window.onbeforeunload = function() {
return "Did you save your stuff?"
}
</script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
window.onbeforeunload = function() {
return "Are you sure?";
};
Run Code Online (Sandbox Code Playgroud)
试试这个吧。