2011-07-15 104 views
0

我有一個簡單的項目,但我在JavaScript的新手, 我需要的是強制鼠標在用戶離開網頁時,在對話框上單擊部隊鼠標點擊

Confirm dialog on leaving page

怎麼做?

回答

0

已在 「卸載」 事件看;)

http://jsfiddle.net/K5FzG/1/

的取出電話,你只需要,如果你打電話給

confirm('Are you sure ?'); 

或類似的評論 「onbeforeunload」 說想要使用頁面中的對象

function goodbye(e) { 
    if(!e) e = window.event; 
    //e.cancelBubble is supported by IE - this will kill the bubbling process. 
    e.cancelBubble = true; 
    e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog 

    //e.stopPropagation works in Firefox. 
    if (e.stopPropagation) { 
     e.stopPropagation(); 
     e.preventDefault(); 
    } 
} 
window.onbeforeunload=goodbye; 
+0

我認爲是更好地使用‘onbeforeunload’保持所有對象的文件活着 – sahid