简体   繁体   English

Chrome中的onunload事件,或者是否有其他解决方法

[英]onunload event in chrome or is there any alternative work arounds

as i searched quite for this issue, including google chrome support sites, Chrome Bug Issues , as they are not yet fixed the problem. 由于我在此问题上进行了充分的搜索,包括google chrome支持网站, Chrome Bug问题 ,因为它们尚未解决。 Right now i have a situation where i should use onuload or onbeforeunload event in my JS Snippets, as its working nicely in other browsers. 现在我有一种情况,我应该在我的JS代码片段中使用onuload或onbeforeunload事件,因为它在其他浏览器中效果很好。 these are the things which i've tried of now 这些是我现在尝试过的东西

  • using Page Hide or PageShow as Webkit provides alternative to this problem, but the result is same, chrome is not firing the onpagehide event only. 将Page Hide或PageShow用作Webkit提供了解决此问题的替代方法,但是结果是相同的,chrome不会仅触发onpagehide事件。 after bit of exploration i come to know pagehide and pageshow methods are applicapble to firefox only. 经过一番探索,我发现pagehide和pageshow方法仅适用于Firefox。
  • Secondly i tried setting Async=false, as suggested in this answer OnUnload . 其次,我尝试按照此答案OnUnload中的建议设置Async = false。
  • I'm using Chrome Dev.Version (17.0.963.12 dev-m). 我正在使用Chrome Dev.Version(17.0.963.12 dev-m)。

Is there any work around for this weird problem, i hope anyone already experienced the same problem, and they may got some alternative. 有什么办法可以解决这个怪异的问题,我希望任何人都已经遇到过同样的问题,并且他们可能会有其他选择。

<html>
<script type="text/javascript" >
function DoSomethingonUnload()
{
alert ('im unloading');

}
</script>
<body onunload="DoSomethingonUnload();"> //need alternative which can work in (ie,chrome,ff)
</body>
</html>

Using jQuery, I achieved this task. 使用jQuery,我完成了这项任务。 Using Bind function with onbeforeunload event jQuery bind . 将Bind函数与onbeforeunload事件一起使用jQuery bind it works seamlessly :) :) thank you @ Sergey Ratnikov 它可以无缝运行:) :)谢谢@ Sergey Ratnikov

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

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