This would better fit in a JavaScript forum, but I wasn't sure if you found a solution yet, so I thought I would put in my 2 cents.
The value returned from ConfirmClose when overriding the onbeforeunload is a string that will appear in the default browser confirm popup.
This should work:
var isNotesNeedToBeSaved = false; //true if notes need to be saved
<body onbeforeunload="return isNotesNeedToBeSaved ? 'Notes need to be saved.' : true">
If for any reason you don't have access to the body tag (as was my case, it is generated from the server before my code) you can insert a script within the body element:
<script ...>
var isNotesNeedToBeSaved = false; //true if notes need to be saved
document.getElementsByTagName("BODY")[0].onbeforeunload = ConfirmClose;
function ConfirmClose()
{
if( isNotesNeedToBeSaved )
return "Notes need to be saved.";
else
document.getElementsByTagName("BODY")[0].onbeforeunload = true;
}
I only tried this in IE.
|