Reply
Overriding onBeforeUnload dialog message
Old 02-09-2006, 08:36 PM Overriding onBeforeUnload dialog message
Junior Talker

Posts: 2
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.

Thanks,
Welles
welles is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 02-10-2006, 04:45 AM Re: Overriding onBeforeUnload dialog message
chrishirst's Avatar
Super Moderator

Posts: 12,661
Location: Blackpool. UK
redefine the function to do what you want by writing your own function called onBeforeUnload()
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-10-2006, 01:15 PM Re: Overriding onBeforeUnload dialog message
Junior Talker

Posts: 2
Thanks for your reply, I already defined a new function for the event but it still doesn't work.

Code:
<script language="javascript">
window.onbeforeunload = onBeforeUnload_Handler;
 
function onBeforeUnload_Handler(){
fConfirm('param1','param2','param3','param3');
}
 
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;
}
}
</script>

Last edited by welles : 02-10-2006 at 01:16 PM.
welles is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Overriding onBeforeUnload dialog message
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11001 seconds with 13 queries