Javascript 'onunload' event not working in latest Version '54.0.2840.71 m' of Google Chrome browser

£可爱£侵袭症+ 提交于 2019-12-12 10:13:11

问题


Recently I updated my Google Chrome browser to Version '54.0.2840.71 m' and suddenly javascript 'onUnload' event has stopped working. I am sure, it was working fine before the upgrade.

In my code (mentioned below), I am trying to open a 'Child' window from a 'Parent' window and when the child window is closed/refreshed (i.e. when its unload event is triggered), it should also reload or refresh the parent window.

Source code of parent.html file:

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

Source Code of child.html file:

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

This code works properly in both 'Internet Explorer' and 'Mozilla Firefox' browsers and it also used to work in earlier version of 'Google Chrome' but not its latest version.

Please let me know if I am doing something incorrectly.

Thanks & Regards!


回答1:


I'm guessing that the event is actually called (as I can add breakpoints and do just about anything else in it) and that window.opener.location.reload() is just being ignored / prevented by this commit: https://chromium.googlesource.com/chromium/src/+/8fb70277dba468aac9d2eae51e432d76667a79db

I've created a bug as well (https://bugs.chromium.org/p/chromium/issues/detail?id=660496) as I'm afraid your bug will be closed due to the previously mentioned discrepancy.



来源:https://stackoverflow.com/questions/40280974/javascript-onunload-event-not-working-in-latest-version-54-0-2840-71-m-of-go

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!