在浏览器停止按钮单击上执行操作 [英] Perform action on browser stop button click
问题描述
道歉,如果这是简单的;我是JQuery的新手。我搜索并找到了诸如这个之类的问题,但他们似乎没有完全回答我的问题。
Apologies if this is simplistic; I am new to JQuery. I have searched and found questions like this, but they don't seem to quite answer my question.
我正在使用JQuery为需要很长时间的操作显示一个愚蠢的进度指示器:
I am using JQuery to show a dumb progress indicator for actions that take a long time:
$(document).ready(function() {
$('form').submit(function() {
$('#progress').show();
});
});
当用户点击表单按钮时,我只显示带有动画gif的div。在页面可见的剩余时间内,此div是可见的。表单操作完成后,将加载新页面。
When the user clicks a form button, I just show a div with an animated gif. This div is visible for the rest of the time the page is visible. After the form's action is complete, a new page loads.
这很有效,但是如果用户在操作完成之前单击浏览器中的停止,该怎么办?怎么能让div消失?有没有办法捕捉这个事件,还是有更好的方法来处理整个情况?
This works well, but what if the user clicks "stop" in the browser before the action completes? How can I make the div disappear? Is there a way to catch this event, or is there a better way to handle the whole situation?
感谢您的帮助。
推荐答案
你可以使用onstop事件来处理这个问题,但它只适用于IE。我认为你不能为其他浏览器处理这样的事件。
You can use "onstop" event to handle this, but it will only work for IE. I think you cannot handle such event for other browsers.
你可以尝试的是让进度对话框在小超时后消失:
What you can try is to make the progress dialog disappear after small timeout:
$('form').submit(function() {
$('#progress').show();
setTimeout(function(){
$('#progress').hide();
},3000);
});
这篇关于在浏览器停止按钮单击上执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!