Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1198 How can I check with the user that they really do want to leave my page?

You are here: irt.org | FAQ | JavaScript | Misc | Q1198 [ previous next ]

Try the following, although its not guaranteed to work in Netscape Navigator:

<html>
<head>
<script language="JavaScript"><!--
function confirmIEleave() {
  event.returnValue = "Are you sure you want to leave this page?";
}

function confirmNSLeave() {
  if (!document.layers) return;
  if (!confirm('Are you sure you want to leave this page?'))
    window.location.href = 'javascript:void(0)';
}
//--></script>
</head>

<body onbeforeunload="confirmIELeave()" onUnload="confirmNSLeave()">

<p>
Navigate to another page to fire the before unload event.
</p>

</body>
</html>

Feedback on 'Q1198 How can I check with the user that they really do want to leave my page?'

©2018 Martin Webb