View Full Version : Overriding onBeforeUnload dialog message

02-10-2006, 02:39 AM
Hi there,

Does anyone know how to suppress the default messages?

1. "Are you sure you want to navigate away from this page?"
2. "Press OK to continue, or Cancel to stay on current page"

I need to provide the user a custome message. I tried many approachs, but non of them seem to work. I tried to use a confirm box instead, but for some reason, the return value for onBeforeUnload event seem to be used as string, so return false to the event CANNOT stop the page from refreshing.


02-10-2006, 11:06 PM
Ok, I just tried to define a new function for the event, but it still doesn't work.

<script language="javascript">
window.onbeforeunload = onBeforeUnload_Handler;

function onBeforeUnload_Handler(){

function fConfirm(p1,p2,p3,p4)

//do something with p1, p2, p3, p4....

//this shows the default dialog box
//event.returnValue = 'Any changes will be lost if you proceed.';

//this shows the custom confirm box, but it doesn't stop the page from

//refreshing even the user click the "Cancel" button
if(!confirm("Any changes will be lost if you proceed.")){
return false;
return true;