2010-09-25 61 views
0

當確定按鈕,用戶點擊重定向如何調用刪除功能,然後繼續之前重定向window.onbeforeunload功能

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

} 
+1

同樣的問題:http://stackoverflow.com/questions/3793662/jquery-confirm-and-exit-functionality有人合併這些pls – Tim 2010-09-25 12:38:07

回答

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

我發現這一點,我們可以使用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() 
{ 

}