Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Overriding onBeforeUnload dialog message

    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

  • #2
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    override onBeforeUnload

    Ok, I just tried to define 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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •