Gmail: the Back button (vs. Close button)...onBeforeUnload?

Discussion in 'Javascript' started by allan.young@gmail.com, Mar 20, 2007.

  1. Guest

    Hi,

    When in gmail I'm composing a new email message and I bit the browser
    back button, I get a dialog that says "Your message has not been sent.
    Discard your message?"

    But if instead of clicking Back, I hit the Browser Close button, I get
    the above message, PLUS if I click "cancel" on that dialog, I get the
    following message 'Are you sure you want to navigate away from this
    page? Press "Cancel" to remain on this page. Press OK to continue, or
    Cancel to stay on the current page.'

    This latter dialog is likely the usual onBeforeUnload() dialog.

    What I don't understand here is why this latter (likely:
    unBeforeUnload) dialog doesn't appear in the case where the user
    clicks "cancel" on the dialog shown when they have hit the Back
    button. Both Back and Close trigger onBeforeUnload.

    Any thoughts?

    Regards,
    Allan
     
    , Mar 20, 2007
    #1
    1. Advertising

  2. Tom Cole Guest

    On Mar 20, 3:39 pm, wrote:
    > Hi,
    >
    > When in gmail I'm composing a new email message and I bit the browser
    > back button, I get a dialog that says "Your message has not been sent.
    > Discard your message?"
    >
    > But if instead of clicking Back, I hit the Browser Close button, I get
    > the above message, PLUS if I click "cancel" on that dialog, I get the
    > following message 'Are you sure you want to navigate away from this
    > page? Press "Cancel" to remain on this page. Press OK to continue, or
    > Cancel to stay on the current page.'
    >
    > This latter dialog is likely the usual onBeforeUnload() dialog.
    >
    > What I don't understand here is why this latter (likely:
    > unBeforeUnload) dialog doesn't appear in the case where the user
    > clicks "cancel" on the dialog shown when they have hit the Back
    > button. Both Back and Close trigger onBeforeUnload.
    >
    > Any thoughts?
    >
    > Regards,
    > Allan


    The second window you see is the result of returning a value from the
    onbeforeunload event handler. If the function you have defined as the
    onbeforeunload handler returns ANYTHING (even null) that little window
    will pop up.

    Try it out.
     
    Tom Cole, Mar 22, 2007
    #2
    1. Advertising

  3. Tom Cole Guest

    On Mar 20, 3:39 pm, wrote:
    > Hi,
    >
    > When in gmail I'm composing a new email message and I bit the browser
    > back button, I get a dialog that says "Your message has not been sent.
    > Discard your message?"
    >
    > But if instead of clicking Back, I hit the Browser Close button, I get
    > the above message, PLUS if I click "cancel" on that dialog, I get the
    > following message 'Are you sure you want to navigate away from this
    > page? Press "Cancel" to remain on this page. Press OK to continue, or
    > Cancel to stay on the current page.'
    >
    > This latter dialog is likely the usual onBeforeUnload() dialog.
    >
    > What I don't understand here is why this latter (likely:
    > unBeforeUnload) dialog doesn't appear in the case where the user
    > clicks "cancel" on the dialog shown when they have hit the Back
    > button. Both Back and Close trigger onBeforeUnload.
    >
    > Any thoughts?
    >
    > Regards,
    > Allan


    Here's a good page that describes what's happening:

    http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript
     
    Tom Cole, Mar 22, 2007
    #3
  4. Guest

    Hi Tom,

    Thanks for your reply.

    What is still not clear to me, even after reading page you suggested,
    is the handling of the case in GMail where the user has a dirty
    document and hits the browser's Back button.

    In this case, GMail shows what appears to be a GMail specific OK|
    Cancel modal dialog. If the user hits OK, no followup dialog is shown,
    so in this case an empty string is probably returned from their
    onbeforeunload handler.

    But, if the user hits Cancel, the browser does not navigate away from
    the dirty document, and the default onbeforeunload query dialog
    doesn't show either. So my question is, in this Cancel case, how is
    Gmail prevent the navigation away from the current page without
    showing this query dialog? What would need to be returned from their
    onbeforeunload handler in order to achieve this?

    Regards,
    Allan
     
    , Mar 22, 2007
    #4
  5. Tom Cole Guest

    On Mar 22, 12:25 pm, wrote:
    > Hi Tom,
    >
    > Thanks for your reply.
    >
    > What is still not clear to me, even after reading page you suggested,
    > is the handling of the case in GMail where the user has a dirty
    > document and hits the browser's Back button.
    >
    > In this case, GMail shows what appears to be a GMail specific OK|
    > Cancel modal dialog. If the user hits OK, no followup dialog is shown,
    > so in this case an empty string is probably returned from their
    > onbeforeunload handler.
    >
    > But, if the user hits Cancel, the browser does not navigate away from
    > the dirty document, and the default onbeforeunload query dialog
    > doesn't show either. So my question is, in this Cancel case, how is
    > Gmail prevent the navigation away from the current page without
    > showing this query dialog? What would need to be returned from their
    > onbeforeunload handler in order to achieve this?
    >
    > Regards,
    > Allan


    I'b be lying if I said this were anything more than a guess, but their
    site uses frames. What I think you're seeing is cimbined behaviour
    from onbeforeunload handlers for two different pages. My guess would
    be that in scenario 1 (backbutton) you're seeing the handler for the
    visible frame, and in scenario 2 (close) your seeing both the handler
    from the visible frame, plus the one from the non-visible frame.
     
    Tom Cole, Mar 22, 2007
    #5
  6. Guest

    Hi Tom,

    Still, whether two frames are used or not, how can a page or frame
    that handles onbeforeunload avoid showing the default browser dialog
    and yet support cancelling of the unload? To my knowledge, the only
    way to cancel the unload is to return a non-empty string in the
    onbeforeunload handler, which causes the browser to show its dialog.
    If you pass an empty string, the page will unload.

    Regards,
    Allan
     
    , Mar 22, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RJN
    Replies:
    1
    Views:
    3,016
    bruce barker
    Sep 29, 2004
  2. sylvia sil
    Replies:
    1
    Views:
    619
    Curt_C [MVP]
    Dec 29, 2004
  3. Author
    Replies:
    6
    Views:
    3,101
    George
    Jan 22, 2009
  4. Iñaki Baz Castillo
    Replies:
    7
    Views:
    870
    Iñaki Baz Castillo
    Jan 12, 2010
  5. Replies:
    2
    Views:
    158
    ulrich kautz
    Aug 16, 2006
Loading...

Share This Page