I have a chat application,i want that whenver user accidentaly closes the browser i want to give him a jquery dialog alert before the window closes and do the necessary clean up operations.Please help
+1
A:
perhaps you'llhave to use window.onbeforeunload
event to get this.
have a look on this page
example usage from that page bound to a form
function setConfirmUnload(on) {
window.onbeforeunload = (on) ? unloadMessage : null;
}
function unloadMessage() {
return 'You have entered new data on this page. If you navigate away from this page without first saving your data, the changes will be lost.';
}
$(document).ready(function() {
$(':input',document.myForm).bind("change", function() { setConfirmUnload(true); }); // Prevent accidental navigation away
});
Wbdvlpr
2009-07-31 08:17:24
Is this IE only?
hamlin11
2009-07-31 08:20:33
+1
A:
View the discussion here: link
Basically, you end up using code like this:
300 jQuery(window).unload(function(e) {
301 var chg = jQuery(".crayon-changed");
302 if (chg.length && uniConfirm(configCrayons.txt.sauvegarder)) {
303 chg.next().find('form').submit();
304 }
305 });
Here is a link to the javascript code here (as shown in the thread i linked to above)
hamlin11
2009-07-31 08:18:37