confirm msg on onUnload?

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

    confirm msg on onUnload?

    Hi,

    Is there anyway to display a confirm msg onUnload of a page?

    I mean to say if iam calling onUnload=javasc ript:check();

    and in check(){

    if(confirm("che ck?"))
    {
    unload the page;
    }
    else
    {
    Dont unload , just come back to the previous state( i have some
    values in text fields to be retained)
    }
    }

    I want to call this function on Unload.
    Suggest me a way.

  • Martin Honnen

    #2
    Re: confirm msg on onUnload?



    Nithya Venkatachalam wrote:
    [color=blue]
    > Is there anyway to display a confirm msg onUnload of a page?
    >
    > I mean to say if iam calling onUnload=javasc ript:check();
    >
    > and in check(){
    >
    > if(confirm("che ck?"))
    > {
    > unload the page;
    > }
    > else
    > {
    > Dont unload , just come back to the previous state( i have some
    > values in text fields to be retained)
    > }
    > }
    >
    > I want to call this function on Unload.[/color]

    You should set
    event.returnVal ue = 'Check?'
    e.g.
    <body onunload="event .returnValue = 'Check?';">
    that is all that is allowed, then your message will appear in the same
    confirmation dialog the default confirmation message is in.

    --

    Martin Honnen

    Comment

    • Michael Winter

      #3
      Re: confirm msg on onUnload?

      On 30 Aug 2004 06:22:00 -0700, Nithya Venkatachalam <vnithya@gmail. com>
      wrote:

      I'm assuming this is for the Web. If you're actually writing something for
      a more restricted environment where you know precisely what browsers will
      be used, say so. The advice might change.
      [color=blue]
      > Is there anyway to display a confirm msg onUnload of a page?[/color]

      The practical answer is no. Whilst you *might* be able to display a
      message or perform some action, you certainly can't prevent the browser
      from closing[1]. The only reliable approach is to ensure you cater for a
      user leaving abnormally (setting automatic session timeouts on the server,
      etc.).

      Moreover, any script approach can be disabled or skipped by a user.
      [color=blue]
      > I mean to say if iam calling onUnload=javasc ript:check();[/color]

      <body ... onunload="check ()">

      [snip]

      Mike


      [1] Granted, IE allows cancellation using onbeforeunload, but not everyone
      uses IE.

      --
      Michael Winter
      Replace ".invalid" with ".uk" to reply by e-mail.

      Comment

      • Martin Honnen

        #4
        Re: confirm msg on onUnload?



        Martin Honnen wrote:
        [color=blue]
        >
        >
        > Nithya Venkatachalam wrote:
        >[color=green]
        >> Is there anyway to display a confirm msg onUnload of a page?
        >>
        >> I mean to say if iam calling onUnload=javasc ript:check();
        >>
        >> and in check(){
        >>
        >> if(confirm("che ck?"))
        >> {
        >> unload the page;
        >> }
        >> else
        >> {
        >> Dont unload , just come back to the previous state( i have some
        >> values in text fields to be retained)
        >> }
        >> }
        >>
        >> I want to call this function on Unload.[/color]
        >
        >
        > You should set
        > event.returnVal ue = 'Check?'
        > e.g.
        > <body onunload="event .returnValue = 'Check?';">[/color]

        That should be
        <body onbeforeunload= "event.returnVa lue = 'Check?';">


        --

        Martin Honnen

        Comment

        Working...