简体   繁体   English

onunload在Chrome和Safari中不起作用

[英]onunload not working in Chrome and safari

I have parent page and child page. 我有父页面和子页面。 In child page body tag i have below code. 在子页面正文标签中,我有以下代码。

<body onunload="window.g_autoclosed=true;if(window.opener&&window.opener.NavModelessClose){window.opener.NavModelessClose(window,false);}"> 

when i click on button in parent page, child page should close and call the onunload event. 当我单击父页面中的按钮时,子页面应关闭并调用onunload事件。

The unload event is raising correctly in IE and FF. IE和FF中的卸载事件正在正确引发。 But it is not raising in chrome and safari. 但这并没有增加铬和野生动物园。

Please help me. 请帮我。

Modern WebKit browsers don't necessarily fire the unload event at the moment where the page is hidden. 现代WebKit浏览器不一定会在页面隐藏时触发unload事件。 This is done in order to allow improved caching. 这样做是为了改进缓存。

You might consider replacing the use of unload with the pagehide event. 您可以考虑使用pagehide事件代替对unload的使用。

See this blog post for an in-depth discussion . 请参阅此博客文章进行深入讨论

Unload works in modern browsers, but for example you cant launch an alert. 卸载可在现代浏览器中使用,但是例如您无法启动警报。 See: http://bugs.jquery.com/ticket/10509 请参阅: http//bugs.jquery.com/ticket/10509

Also if you want to use $.get or $.post in unload, is better that you use $.ajax with async=false. 另外,如果要在卸载中使用$ .get或$ .post,最好将$ .ajax与async = false一起使用。

Ex: 例如:

$(window).unload(function() {
            $.ajax({
              url: '/some_url.htm',
              async: false
            });
    });

也许尝试onbeforeunload事件?

是的,附加到窗口(或子页面的内部窗口)的onbeforeunload应该这样做

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM