location.replace() in the onUnload event?

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

    location.replace() in the onUnload event?

    Hi,

    I am only writing for IE 5.5+ so no need for compatibility at all ;-)

    I am trying to get my users to logoff which they finish on a particular
    page. This is no problem (or should be no problem) as I can just put a
    location.replac e('http://www.mysite.com/html/logoff.jsp'); into the onUnload
    event of the page they always finish on. This should fire when they click
    the X in the corner (my app. is in a popup window) instead of hitting exit.

    Unfortunately this won't work for me as it won't go to the page from the
    onUnload= event unless I put an alert box in the method called like this:
    (Example 1 does not work):

    function endSession()
    {
    if(!submitting)
    {
    // end session.
    location.replac e('http://www.mysite.com/jsp/logoff.jsp');
    }
    return false;
    }


    function endSession()
    {
    if(!submitting)
    {
    // end session.
    location.replac e('http://www.mysite.com/jsp/logoff.jsp');
    alert('in endSession()');
    }
    return false;
    }

    Can anyone shed any light on why the second one works? What can I use
    instead of an alert box?

    Thanks in advance,

    Andoni.


  • Martin Honnen

    #2
    Re: location.replac e() in the onUnload event?



    Andoni wrote:
    [color=blue]
    > Hi,
    >
    > I am only writing for IE 5.5+ so no need for compatibility at all ;-)
    >
    > I am trying to get my users to logoff which they finish on a particular
    > page. This is no problem (or should be no problem) as I can just put a
    > location.replac e('http://www.mysite.com/html/logoff.jsp'); into the onUnload
    > event of the page they always finish on. This should fire when they click
    > the X in the corner (my app. is in a popup window) instead of hitting exit.
    >
    > Unfortunately this won't work for me as it won't go to the page from the
    > onUnload= event unless I put an alert box in the method called like this:
    > (Example 1 does not work):
    >
    > function endSession()
    > {
    > if(!submitting)
    > {
    > // end session.
    > location.replac e('http://www.mysite.com/jsp/logoff.jsp');
    > }
    > return false;
    > }
    >
    >
    > function endSession()
    > {
    > if(!submitting)
    > {
    > // end session.
    > location.replac e('http://www.mysite.com/jsp/logoff.jsp');
    > alert('in endSession()');
    > }
    > return false;
    > }
    >
    > Can anyone shed any light on why the second one works? What can I use
    > instead of an alert box?[/color]

    You can open a logoff window with
    <body onunload="windo w.open('logon.j sp');">
    then logon.jsp can call
    <body onload="window. close();">
    if you so desire.

    --

    Martin Honnen


    Comment

    • Andoni

      #3
      Re: location.replac e() in the onUnload event?

      Thanks for this, I was just reading the M$ site when I noticed that my
      location.replac e was itself also calling the onUnload event! You are right,
      this way works well, thanks.

      Andoni.


      "Martin Honnen" <Martin.Honnen@ t-online.de> wrote in message
      news:3f744d9a$1 @olaf.komtel.ne t...[color=blue]
      >
      >
      > Andoni wrote:
      >[color=green]
      > > Hi,
      > >
      > > I am only writing for IE 5.5+ so no need for compatibility at all ;-)
      > >
      > > I am trying to get my users to logoff which they finish on a particular
      > > page. This is no problem (or should be no problem) as I can just put a
      > > location.replac e('http://www.mysite.com/html/logoff.jsp'); into the[/color][/color]
      onUnload[color=blue][color=green]
      > > event of the page they always finish on. This should fire when they[/color][/color]
      click[color=blue][color=green]
      > > the X in the corner (my app. is in a popup window) instead of hitting[/color][/color]
      exit.[color=blue][color=green]
      > >
      > > Unfortunately this won't work for me as it won't go to the page from the
      > > onUnload= event unless I put an alert box in the method called like[/color][/color]
      this:[color=blue][color=green]
      > > (Example 1 does not work):
      > >
      > > function endSession()
      > > {
      > > if(!submitting)
      > > {
      > > // end session.
      > > location.replac e('http://www.mysite.com/jsp/logoff.jsp');
      > > }
      > > return false;
      > > }
      > >
      > >
      > > function endSession()
      > > {
      > > if(!submitting)
      > > {
      > > // end session.
      > > location.replac e('http://www.mysite.com/jsp/logoff.jsp');
      > > alert('in endSession()');
      > > }
      > > return false;
      > > }
      > >
      > > Can anyone shed any light on why the second one works? What can I use
      > > instead of an alert box?[/color]
      >
      > You can open a logoff window with
      > <body onunload="windo w.open('logon.j sp');">
      > then logon.jsp can call
      > <body onload="window. close();">
      > if you so desire.
      >
      > --
      >
      > Martin Honnen
      > http://JavaScript.FAQTs.com/
      >[/color]


      Comment

      • Richard Cornford

        #4
        Re: location.replac e() in the onUnload event?

        "Andoni" <andoni@REMOVE. indigo.ie> wrote in message
        news:bl1j1d$kmm $1@kermit.esat. net...[color=blue]
        >Thanks for this, I was just reading the M$ site when I
        >noticed that my location.replac e was itself also calling
        >the onUnload event! You are right, this way works well,
        >thanks.[/color]

        If you are writing exclusively for IE 5.5+ you might be better off using
        the onbeforeunload event.

        Richard.


        Comment

        Working...