window.onbeforeunload功能

时间:2010-09-25 12:34:28

标签: javascript jquery javascript-events jquery-selectors

当用户在重定向如何调用删除功能然后继续重定向之前单击确定按钮

 $(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 个答案:

答案 0 :(得分:2)

$(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()
{

} 

答案 1 :(得分:1)

我发现了这个,我们可以使用window.unload,如图所示。谢谢

$(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()
{

}