本文介绍了当我关闭窗户时做一个动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在设计一个应用程序,但我想知道我应该使用哪个事件,以便在我关闭窗口时执行一个操作.
我尝试使用window.close
,但是当我加载/转到网站时它会执行操作,而当我想要关闭它时则不执行操作,这就是我想要的.
Hello, I''m designing an app but I want to know what event I should use for that an action will be done when I''ll close the window.
I''ve tried with window.close
but it does the action when I load/go to the website and no when i want to close it, that is what i want that it does.
推荐答案
<pre>function closeIt() {<br />
alert(''HI'');<br />
}<br />
window.onbeforeunload = closeIt;</pre><br />
而且没有这样(像这样我有问题):
and no like this (like this i had the problem):
window.onbeforeunload = alert(''Bye, bye'');
非常感谢您的帮助
问候
Thanks very much for your help
Regards
这篇关于当我关闭窗户时做一个动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!