如何捕捉 xulrunners close 事件并取消它?
当用户单击主窗口的关闭按钮并要求他们确认时,我想捕获 xulrunner 应用程序的关闭事件。如果他们不确认,我想取消此关闭事件并继续应用程序。
我尝试了 OnClose 事件,但无法取消它。
我如何实现这个?
I want to catch the close event of my xulrunner app when user clicks the close button of the main window and ask them for confirmation.If they dont confirm ,i want to cancel this close event and continue the application.
I tried OnClose Event ,but i was not able to cancel it.
How do i implement this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能需要两种不同的东西:
1)在窗口关闭时进行提示。您可以使用“关闭”事件,例如:
我刚刚检查了它,它确实有效。
2)应用程序即将退出时进行提示。您可以通过 nsIObserverService (< a href="https://developer.mozilla.org/en/nsIObserver#Example_Code" rel="nofollow noreferrer">示例)。
(1) 更接近您的要求,因为当用户按下窗口上的 [X] 按钮时,事件顺序是这样的:
另一方面,如果您仅将检查放在窗口的 onclose 处理程序中,则退出应用程序的其他方式(Win 上的文件退出/Mac 上的退出)可能会太晚触发它(例如,在关闭其他窗口后)。另外,如果您的应用程序可以有多个“主”窗口(带有 onclose 逻辑),则用户将必须处理多个确认,这可能是您想要的,也可能不是您想要的。
以下是 Firefox 代码的一些参考(如果我没有遗漏的话,它也应该与您的应用程序打包在一起),您可以研究并重用所采取的方法:
There are two different things you may want:
1) prompting when a window is closed. You can use the "close" event, e.g.:
I just checked it and it does work.
2) prompting when the application is about to quit. You can do this by observing the quit-application-requested notification via the nsIObserverService (example).
(1) is closer to what you asked, since when the user presses the [X] button on the window, the sequence of events is this:
On the other hand, if you put your check solely in the onclose handler of the window, other ways of quitting application (File-Exit on Win/-Quit on Mac) may trigger it too late (e.g. after closing other windows). Also, if your app can have more than one "main" window (with onclose logic), the user will have to deal with multiple confirmations, which may or may not be what you want.
Here are some references to the Firefox code (if I'm not missing something, it should also be packaged with your application), you can research and reuse the approach taken:
对于其他人,您也可以将
其放在主窗口中
For anyone else looking, you can also do this
put this in the main window
对于程序化且符合 DOM 级别 2 的要求,请回答 Nickolay 的评论 (1):
for a programmatic, and DOM level 2-compliant, answer to Nickolay's remark (1):