这段代码在 Firefox 上运行良好,但我不能再让卸载事件在 Chrome 上运行。Chrome 是否停止支持卸载事件?
这是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="../jquery/jquery.js"></script>
<script type="text/javascript">
function pageHidden(evt) { alert("Are you sure 1?"); } //WORKS ON FIREFOX BUT NOT IN CHROME
window.addEventListener("pagehide", pageHidden, false);
window.onunload = function () { alert("Are you sure 2?"); } //TRIGGERS ON LOAD NOT ON UNLOAD
$(window).unload(function () { //WORKS ON FIREFOX BUT NOT IN CHROME
alert("Are you sure 3?");
});
</script>
</head>
<body>
TEST WEBSITE
<a href="http://www.iamawesome.com">external link</a>
</body>
</html>
如何让卸载事件在 Chrome 中工作?
谢谢!
答案:不要使用警报测试卸载事件;)