2
我已經寫了一個函數,在刷新(我需要它出於某種原因)之前警告用戶。 我也想實現的是,如果用戶點擊Leave this page
,則調用另一個函數。如果用戶點擊stay on this page
我不得不做任何事情。如何知道window.onbeforeunload中的用戶響應
function warnuser()
{
return "Don't refresh the page.";
}
window.onbeforeunload = warnuser;
//if returns true call another function!
謝謝。
這是一個有趣的話題。檢查這是否有幫助http://stackoverflow.com/questions/2103881/capture-user-response-when-using-window-onbeforeunload –