最近我将我的 Google Chrome 浏览器更新为版本 '54.0.2840.71 m' 并且突然 javascript 'onUnload' 事件停止工作。我敢肯定,它在升级之前工作正常。
在我的代码(如下所述)中,我试图从“父”窗口打开一个“子”窗口,当子窗口关闭/刷新时(即触发其卸载事件时),它还应该重新加载或刷新父窗口。
parent.html 文件源代码:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Parent Page</title>
</head>
<body>
This is parent page. Click <a href="#" onClick="window.open('child.html', '_blank', 'toolbar=no,scrollbars=yes,resizable=no,top=150,left=250,width=500,height=500'); return false;">here</a> to open the child page.
</body>
</html>
child.html 文件源代码:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Child Page</title>
<script type="text/javascript">
window.onunload = refreshParent;
function refreshParent() {
window.opener.location.reload();
}
</script>
</head>
<body>
This is child page.
</body>
</html>
此代码在“Internet Explorer”和“Mozilla Firefox”浏览器中都可以正常工作,并且它也可以在早期版本的“Google Chrome”中工作,但不能在最新版本中工作。
如果我做错了什么,请告诉我。
感谢和问候!