views:

36

answers:

2

When the user click on the OK button before redirecting how to call the delete function and then continue redirecting

 $(document).ready({
window.onbeforeunload = confirmExit ;

 });

  function confirmExit()
 {
  var ele = document.getElementById ("localchanges") ;
 if (ele.value == "1")
   return "Changes are not saved. Discard changes?" ;
 }



function delete()
{

} 
+2  A: 
$(document).ready({
window.onbeforeunload = confirmExit ;

 });

  function confirmExit()
 {
 delete()// call delete function here , once this is done , below codes will be executed
  var ele = document.getElementById ("localchanges") ;
 if (ele.value == "1")
   return "Changes are not saved. Discard changes?" ;
 }



function delete()
{

} 
JapanPro
A: 

I found this ,we can use window.unload as shown.Thanks

$(document).ready({
window.onbeforeunload = confirmExit ;
 window.onunload = function() { return delete(); }
});

function confirmExit()
{
 var ele = document.getElementById ("localchanges") ;
 if (ele.value == "1")
 return "Changes are not saved. Discard changes?" ;
}



function delete()
{

} 
Hulk