You can't change the "Are you sure you want to navigate away from this page?" or the "Press OK to continue, or Cancel to stay on the current page" parts. The only thing that you have control over is the middle part of the message.
I just tested this piece of code and it seems to work.
<script type="text/JavaScript">
<!--
var g_isOkToClose = false;
window.onbeforeunload = function ()
{
if ( g_isOkToClose == true )
return;
var closeMessage =
'You will be logged out of the chat room\n' +
'Are you sure you want to exit?';
if ( window.event )
{
// IE only...
window.event.returnValue = closeMessage;
}
else
{
// Other browsers NOTE: Not tested...
return closeMessage;
}
g_isOkToClose = false;
}
// -->
</script>
Add to the CodeBehind, PageLoad event handler to stop the message from showing on PostBacks/submits:
Page.RegisterOnSubmitStatement("OnSubmitScript", "g_isOkToClose = true;");
NC...