How to warn user not to leave the page? [duplicate]
Possible Duplicates:
How can I ask a web user for confirmation if he really wants to leave the page? Client/JS Framework for “Unsaved Data” Protect开发者_运维问答ion?
Like stackoverflow does on the ask page, when I click the close button or any other link on the site a dialog pops up asking if you're sure you want to navigate away from the page. How to do that in javascript or jQuery and can you customize the text in the box?
You want to listen to the onbeforeunload
event:
window.onbeforeunload = function (e) {
return 'Are you sure?';
};
https://developer.mozilla.org/en/DOM/window.onbeforeunload
精彩评论