[英]how to use window onunload event in backbone view
I am fairly new to backbone and I wanted to use window onunload event with one of my view. 我对骨干网还很陌生,我想将window onunload事件与我的一种视图一起使用。 Actually I have created a view for my html page and I want to call some function at the unload of that page. 实际上,我已经为我的html页面创建了一个视图,并且我想在该页面卸载时调用一些函数。 This page is loaded inside a iframe or in a window.open and hence when the window is closed I want to call a function. 将此页面加载到iframe或window.open中,因此,当窗口关闭时,我想调用一个函数。 But the event doesnt fire when I write 但是当我写这篇文章时,事件并没有触发
events: {
"beforeunload window": "myalert"
}
or 要么
$(window).on("beforeunload", myalert);
I saw some threads saying we should use route for this purpose but didn't got some good guide for it. 我看到一些线程说我们应该为此使用路由,但是并没有很好的指导。 Some suggestions/help will be appriciated. 一些建议/帮助将被应用。
Thank you. 谢谢。
One solution between numerous solution is to have your view listen to an event that your window will trigger, here's an example: 众多解决方案之间的一种解决方案是让您的视图侦听窗口将触发的事件,下面是一个示例:
In your view: 您认为:
Backbone.Events.once('windowClosed', myalert');
window.open('your new window url here');
And in the new window, when you want to close it: 在新窗口中,当您要关闭它时:
$(window).on("unload", function() {
window.opener.Backbone.Events.trigger('windowClosed');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.