determine cause of onbeforeunload

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

    #1

    determine cause of onbeforeunload

    If I want to show a closing message ONLY if the user is trying to
    close the browser, I need to determine the cause of onbeforeunload
    being called.

    The following attempts do NOT work:
    checking document.active Element for the BODY tag
    setting flags in window.onbefore unload/onfocus or body.onactivate ,
    body.ondeactive

    Any ideas?

    Thanks
    Eric
  • Randy Webb

    #2
    Re: determine cause of onbeforeunload

    Eric Robishaw wrote:
    [color=blue]
    > If I want to show a closing message ONLY if the user is trying to
    > close the browser, I need to determine the cause of onbeforeunload
    > being called.[/color]

    You can't. Script can only tell that I left, not how I left. And even
    determining that I left is not always reliable.
    [color=blue]
    > The following attempts do NOT work:
    > checking document.active Element for the BODY tag
    > setting flags in window.onbefore unload/onfocus or body.onactivate ,
    > body.ondeactive
    >
    > Any ideas?[/color]

    Why do you need a "closing message" only if I am closing the browser? I
    am leaving the site....

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javas cript FAQ - http://jibbering.com/faq/

    Comment

    • Martin Honnen

      #3
      Re: determine cause of onbeforeunload



      Eric Robishaw wrote:
      [color=blue]
      > If I want to show a closing message ONLY if the user is trying to
      > close the browser, I need to determine the cause of onbeforeunload
      > being called.[/color]

      There are events fired when someone clicks a link or a submit button of
      a form so you can certainly determine such cases and in that case disable
      window.onbefore unload = null
      or set a flag e.g.
      var linkClicked = false;

      <a href="whatever. html"
      onclick="window .linkClicked = true;
      return true;">link</a>
      and in you onbeforeunload handler you check
      if (linkClicked) {
      // set the returnValue here if wanted or unset it if wanted
      }

      --

      Martin Honnen
      http://JavaScript.FAQTs.com/

      Comment

      • Eric Robishaw

        #4
        Re: determine cause of onbeforeunload

        If the browswer is closing I need to warn the user.. giving them a
        chance to save the data changes.

        If, however, we're going to a link on the same site, I'll save the
        changes automatically on the postback... thus making a notification to
        the user not only unnecessary, but annoying.

        Thanks
        Eric











        Randy Webb <hikksnotathome @aol.com> wrote in message news:<xbudneDiM 5s3D1XdRVn-iQ@comcast.com> ...[color=blue]
        > Eric Robishaw wrote:
        >[color=green]
        > > If I want to show a closing message ONLY if the user is trying to
        > > close the browser, I need to determine the cause of onbeforeunload
        > > being called.[/color]
        >
        > You can't. Script can only tell that I left, not how I left. And even
        > determining that I left is not always reliable.
        >[color=green]
        > > The following attempts do NOT work:
        > > checking document.active Element for the BODY tag
        > > setting flags in window.onbefore unload/onfocus or body.onactivate ,
        > > body.ondeactive
        > >
        > > Any ideas?[/color]
        >
        > Why do you need a "closing message" only if I am closing the browser? I
        > am leaving the site....[/color]

        Comment

        • Lee

          #5
          Re: determine cause of onbeforeunload

          Eric Robishaw said:
          [color=blue]
          >Randy Webb <hikksnotathome @aol.com> wrote in message[color=green]
          >> Why do you need a "closing message" only if I am closing the browser? I
          >> am leaving the site....[/color][/color]
          [color=blue]
          >If the browswer is closing I need to warn the user.. giving them a
          >chance to save the data changes.
          >
          >If, however, we're going to a link on the same site, I'll save the
          >changes automatically on the postback... thus making a notification to
          >the user not only unnecessary, but annoying.[/color]

          [Please don't top-post. Add your response *after* what
          you're replying to, so it can be read top to bottom.]


          Randy is pointing out that you've overlooked the other option.
          What if the user is not closing the browser and is not going
          to a link on the same site?

          And you certainly can't detect the fact that they've gotten
          sleepy and have decided to turn the computer off and go to bed,
          without closing the browser.

          The answer is that either your users understand web browsers
          well enough to know that they haven't saved their entries
          unless they've hit a submit button, or a web browser is not
          an appropriate user interface for them to be using.

          Comment

          • kaeli

            #6
            Re: determine cause of onbeforeunload

            In article <90f8e6ff.04061 11050.6d6b7b9f@ posting.google. com>,
            erobishaw@getin theword.com enlightened us with...[color=blue]
            > If the browswer is closing I need to warn the user.. giving them a
            > chance to save the data changes.
            >
            > If, however, we're going to a link on the same site, I'll save the
            > changes automatically on the postback... thus making a notification to
            > the user not only unnecessary, but annoying.
            >[/color]

            This is not acceptable behavior for an internet application - there are
            too many ways a user can leave the site besides closing the browser,
            plus some users don't have javascript enabled at all. What should happen
            if the user grabs a URL from the favs? What if they type it? What if
            they click a link in mail and it re-uses the window (mine does that)?
            What if the browser crashes? What if the next version of Mozilla lets
            users disable this feature (onunload)?

            For an intranet application, it is acceptable, but still unnecessary if
            the application is programmed properly.

            One way to handle this is by storing data in active sessions. If the
            user doesn't save the data, it is autosaved (or you notify the user via
            mail or some such if possible) when the session expires (sessions expire
            a certain amount of time after the browser is closed). A good example of
            this is the shopping cart at amazon (I think that's where it was). If
            you put stuff in your cart, but don't check out, they send you a mail
            asking you if you still wanted the items and giving you a chance to
            still buy them. If you don't respond in a certain amount of time, the
            items are removed from the cart.

            --
            --
            ~kaeli~
            With her marriage, she got a new name and a dress.



            Comment

            Working...