hide onbeforeunload dialog box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alhalayqa
    New Member
    • Mar 2008
    • 11

    #1

    hide onbeforeunload dialog box

    Hi Guys,

    I have attached the beforeunload event and its handler to the window as :

    // this is FireFox only
    window.addEvent Listener("befor eunload",before unloadHandler,f alse);

    function beforeunloadHan dler(event){

    event.returnVal ue="my message !";

    }

    now the string "my message !" will be display on a confirm dialog box ,
    my question could I hide that dialog box, or at least prevent it from being shown .

    of course my goal is to prevent the default behavior of the beforeunload event .
    I have tried event.preventDe fault(). I get the dialog box again .

    any comments ?




    thanks .
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    I doubt this can be done or at least I have not seen a way to prevent the dialog box. It's there for usability, otherwise you could force someone to stay on the page unless they disable JavaScript.

    Comment

    • alhalayqa
      New Member
      • Mar 2008
      • 11

      #3
      Originally posted by acoder
      I doubt this can be done or at least I have not seen a way to prevent the dialog box. It's there for usability, otherwise you could force someone to stay on the page unless they disable JavaScript.
      what about method overriding such as :

      window.confirm = function (){ }

      I have tried that, but still the dailog box appears .

      but are there any other ways to detect that this window will be unloaded . of course without any alerts or confirm boxs .

      thanks .

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        The onbeforeunload dialog box is not the same as the JavaScript confirm() method.

        The alternative to onbeforeunload is, of course, onunload. The problem is that once onunload fires, you can't ask the user to stay on the page.

        Why do you want to prevent the default behaviour?

        Comment

        • alhalayqa
          New Member
          • Mar 2008
          • 11

          #5
          Originally posted by acoder
          The onbeforeunload dialog box is not the same as the JavaScript confirm() method.

          The alternative to onbeforeunload is, of course, onunload. The problem is that once onunload fires, you can't ask the user to stay on the page.

          Why do you want to prevent the default behaviour?
          well, simply I want to detect which url will unload my current document, since beforeunload event could be stopped by the user (dialog box), then this would be annoying for users.

          now, inside the unload event handler, could I know which url will replace my current document . of course I cann't stop the unload event, but at least I want to know the url .

          thanks.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by alhalayqa
            well, simply I want to detect which url will unload my current document, since beforeunload event could be stopped by the user (dialog box), then this would be annoying for users.

            now, inside the unload event handler, could I know which url will replace my current document . of course I cann't stop the unload event, but at least I want to know the url .

            thanks.
            I don't think you can. If you try to get information from the History object, you'll probably get a permission denied warning.

            Comment

            Working...