2

最近我将我的 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”中工作,但不能在最新版本中工作。

如果我做错了什么,请告诉我。

感谢和问候!

4

1 回答 1

0

我猜这个事件实际上是被调用的(因为我可以添加断点并在其中做任何其他事情)并且 window.opener.location.reload() 只是被这个提交忽略/阻止:https:// chromium.googlesource.com/chromium/src/+/8fb70277dba468aac9d2eae51e432d76667a79db

我也创建了一个错误(https://bugs.chromium.org/p/chromium/issues/detail?id=660496),因为我担心您的错误会由于前面提到的差异而关闭。

于 2016-10-28T20:41:31.933 回答