JavaScript + onbeforeunload [英] JavaScript + onbeforeunload
本文介绍了JavaScript + onbeforeunload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对我的申请有疑问。每当用户意外关闭浏览器窗口时,我都希望在此之前进行一些清理操作。我已经使用过onunload事件,但问题是这个事件有时会被解雇,有时却没有。我该怎么办,是否有更好的方法来处理这类问题。
I have a query regarding my application. Whenever user closes browser window accidentally I'd want to do some clean up operations before that. I have used onunload event but problem is this event is sometimes is firing and sometimes doesn't. What should I do, is there better way to handle such type of problem.
推荐答案
window.onbeforeunload = function() {
return 'You have unsaved changes!';
}
此外还有类似问题在SO
这篇关于JavaScript + onbeforeunload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文