Firefox close forbid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Skot

    Firefox close forbid

    Hello,
    Is exiting a possibility to forbid the click on the close cross ?
    Otherwise, can we put a js treatment in order to don't lose the informations
    on the form ?

    Thanks, Skot.


  • RobG

    #2
    Re: Firefox close forbid

    Skot wrote:[color=blue]
    > Hello,
    > Is exiting a possibility to forbid the click on the close cross ?[/color]

    No.
    [color=blue]
    > Otherwise, can we put a js treatment in order to don't lose the informations
    > on the form ?[/color]

    Firefox and Mozilla support 'window.onbefor eunload' (though it doesn't
    seem to have made it into the on-line documentation yet) that allows you
    to prompt a user to not close a window.


    <script type="text/javascript">

    window.onbefore unload = function() {alert('hi'); return false;};

    </script>

    [color=blue]
    >
    > Thanks, Skot.
    >
    >[/color]


    --
    Rob

    Comment

    • Michael Winter

      #3
      Re: Firefox close forbid

      On 03/10/2005 01:33, RobG wrote:

      [snip]
      [color=blue]
      > window.onbefore unload = function() {alert('hi'); return false;};[/color]

      A beforeunload listener should return a string. This string will be
      displayed in a dialog box that asks whether the user wishes to navigate
      away from the current document. So,

      window.onbefore unload = function() {return 'Hi';};

      would be more appropriate.

      You can't cancel the event programatically ; the whole point is for the
      user to handle it.

      Mike

      --
      Michael Winter
      Prefix subject with [News] before replying by e-mail.

      Comment

      • RobG

        #4
        Re: Firefox close forbid

        Michael Winter wrote:[color=blue]
        > On 03/10/2005 01:33, RobG wrote:
        >
        > [snip]
        >[color=green]
        >> window.onbefore unload = function() {alert('hi'); return false;};[/color]
        >
        >
        > A beforeunload listener should return a string. This string will be
        > displayed in a dialog box that asks whether the user wishes to navigate
        > away from the current document. So,
        >
        > window.onbefore unload = function() {return 'Hi';};
        >
        > would be more appropriate.
        >
        > You can't cancel the event programatically ; the whole point is for the
        > user to handle it.[/color]

        Thanks Mike.

        I couldn't find any documentation on the Mozilla site (it seems to be a
        fairly recent inclusion), the Microsoft doco wasn't very clear - their
        example used window.event.

        Hopefully the following is better:


        function savePrompt()
        {
        var unsavedData = true;

        // Do some test to determine if there is unsaved data
        // if unsavedData = true, message is shown
        // if unsavedData = false, navigation is not interrupted

        if ( unsavedData ){
        var message = 'You have unsaved data.'
        + '\nLeaving this page without saving'
        + ' will cause the data to be lost';
        return message;
        }
        }

        window.onbefore unload = savePrompt;



        --
        Rob

        Comment

        Working...