在 chrome 浏览器中单击关闭选项卡图标时尝试调用浏览器选项卡关闭事件但不起作用。我想在关闭浏览器选项卡之前显示警告消息。怎么做?
下面的代码不起作用:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<script type="text/javascript">
window.onbeforeunload = function(evt) {
var message = "Are you sure?";
/* InternetExplorer/Firefox*/
var e = evt || window.event
e.returnValue = message
/* WebKit browser */
return message;
}
</script>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
一只甜甜圈
ITMISS
拉莫斯之舞
相关分类