用户关闭窗口选项卡时的Javascript警报 [英] Javascript alert when user closes the tab ot the window
本文介绍了用户关闭窗口选项卡时的Javascript警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望当用户关闭标签页或窗口时,或者当他尝试移动到与我的站点不同的另一个位置以弹出确认框时,以及如果他确认执行ajax脚本然后关闭或更改窗口。我不知道该怎么做。 PS:我正在使用jQuery。
I want when a user closes the tab or window or when he tries to move to another location different from my site to pops a confirm box, and if he confirm to execute an ajax script and then to close or change the window. I don't know how to do that. PS: I'm using jQuery.
推荐答案
$(window).unload(function() {
var answer=confirm("Are you sure you want to leave?");
if(answer){
//ajax call here
}
});
只需将自己的提醒/对话代码添加到该功能中。
Just add your own alert/dialogue code to the function.
这篇关于用户关闭窗口选项卡时的Javascript警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文