2011-12-12 102 views
4

我想通知我的服務器,用戶已關閉瀏覽器選項卡/窗口與我們的應用程序。ajax和onbeforeunload

我發現運行ajax調用async:false綁定到window.beforeunload evet將工作,它會。排序... ...

window.onbeforeunload = beforeunload; 

function beforeunload() 
{ 
    setSendingPowerStatus(false, true); 

} 

所以,在用戶關閉正在執行的窗口,setSendingPowerStatus(false, true);功能,在它的實施,使得同步調用並在完成後關閉瀏覽器選項卡。另一方面,在FF中,用戶會看到提示的提示對話框,「你確定要離開頁面嗎?」

我的問題是如何執行ajax調用onbeforeunload事件沒有顯示任何對話框?我的意思是我想執行一個Ajax調用窗口前,而不會打擾用戶關閉...

我也試圖回假也從我的處理函數,但沒有運氣有要麼...

回答

0

我建議你重試那樣(設置returnValue爲true,並返回true):

function beforeunload(event) 
{ 
    setSendingPowerStatus(false, true); 
    event.returnValue=true; 
    return true; 
} 
window.onbeforeunload = beforeunload;