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.
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.
Share Improve this question asked Jun 8, 2011 at 14:18 NikolayNikolay 1652 silver badges14 bronze badges 2- 2 Please stop asking duplicate questions. If you need to revise your question, simply edit it. – user50049 Commented Jun 8, 2011 at 14:53
- 1 Also, would it kill you to accept some answers to your questions? 14% is a dismal acceptance rating no matter the reason. – Chris Commented Jun 8, 2011 at 15:08
2 Answers
Reset to default 5$(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.
<script language="JavaScript">
function unload() {
alert('window closed');
}
window.onunload = unload;
</script>