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>