在 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>