Home Search Member List Faq Register Login  
JavaScript Tips
Display confirmation before the page is closed

Thread Starter: Karamasoft   Started: 09-04-2007 7:09 PM   Replies: 0
 Karamasoft Support Forums » General Discussions » JavaScript Tips » Display confirmation before the page is closed
 Printable Version    « Previous Thread   Next Thread »
  04 Sep 2007, 7:09 PM
Karamasoft is not online. Last active: 5/8/2018 10:36:45 AM Karamasoft

Top 10 Posts
Joined on 09-05-2004
Posts 6,820
Display confirmation before the page is closed

If you need to display a confirmation before the user closes the window, you can use the beforeunload event of the window object to display a confirmation message.

JavaScript
function AddUnloadHandler() {
 AddEventHandler(window, 'beforeunload', HandleUnload);
}

function HandleUnload() {
 var strConfirm = 'Please make sure you saved your changes before closing the page.';
 if (document.all) {
  window.event.returnValue = strConfirm;
 }
 else {
  alert(strConfirm);
  var evnt = arguments[0];
  evnt.stopPropagation();
  evnt.preventDefault();
 }
}

ASPX
<body onload="AddUnloadHandler()">


  
 Page 1 of 1 (1 items)
Karamasoft Support Forums » General Discussions » JavaScript Tips » Display confirmation before the page is closed

You can add attachments
You can post new topics
You can reply to topics
You can delete your posts
You can edit your posts
You can create polls
You can vote in polls
Forum statistics are enabled
Forum is unmoderated

© 2002-2018 Karamasoft LLC. All rights reserved.