onunload and redirect

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

    #1

    onunload and redirect

    I am trying to use the onunload event to know when the user closes a
    popup by receiving a request on the web server.

    I have a main page from where the user opens a popup. What I want is
    when the user closes the popup, it sends a request to my web server
    (GoAhead) using the onunload event, then closes the popup.

    For the moment, this what i have: when the user closes the popup, I
    use the onunload event to open a different popup (by this way, I get a
    request on the web server and I know that the user closes the first
    popup), then, this new popup closes itself with the onload event. It
    is working but having this second popup opening and closing is not
    very neat.

    If I try to change the location of the first popup in the onunload
    event: onunload="docum ent.location='. ...'", it doesn't send a request
    to the web server when the user closes the popup.

    Is there a way to send a request to the webserver when the user closes
    the popup without the need to have an extra popup opened and closed ?

    The web server I am using is working on a pseudo "cgi" mode called
    "goforms", it avoids to create a different process for each request.
    With "goforms", each request is handled by a unique process which is
    always running.

    Laurent
  • Erwin Moller

    #2
    Re: onunload and redirect

    Hi Laurent,

    Try this:
    1) On you mainpage: create a hidden frame (size=0 and such)
    2) Your pop-up calls a javascriptfunct ion in the mainframe when closed, then
    closes.

    onUnLoad='opene r.tellTheServer ();';

    3) This javascriptfunct ion loads the page you want in the hidden frame.

    Regards,
    Erwin Moller

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: onunload and redirect

      Laurent wrote:[color=blue]
      > I am trying to use the onunload event to know when the user closes a
      > popup by receiving a request on the web server.[/color]

      Unless you can *guarantee* that the user cannot navigate to another
      document within the popup, this is not a viable solution as the onunload
      event will fire then, too. And you cannot guarantee this, unless this
      is for a very restricted Intranet. There is the `onclose' event handler
      in the IE DOM, but the same restriction applies here.
      [color=blue]
      > I have a main page from where the user opens a popup. What I want is
      > when the user closes the popup, it sends a request to my web server
      > (GoAhead) using the onunload event, then closes the popup.[/color]

      What if client-side scripting is disabled or not even present?
      [color=blue]
      > For the moment, this what i have: when the user closes the popup, I
      > use the onunload event to open a different popup (by this way, I get a
      > request on the web server and I know that the user closes the first
      > popup),[/color]

      You cannot know for sure, unless ... (see above).
      [color=blue]
      > If I try to change the location of the first popup in the onunload
      > event: onunload="docum ent.location='. ...'", it doesn't send a request
      > to the web server when the user closes the popup.[/color]

      `document.locat ion' has been deprecated a long time ago. Use
      `window.locatio n'.
      [color=blue]
      > Is there a way to send a request to the webserver when the user closes
      > the popup without the need to have an extra popup opened and closed ?[/color]

      There is a way to send a request to the Web server if the `unload' event
      fires (or on any other occasion). It is called XML HTTP Request and
      implemented with the XMLHttpRequest object in the Gecko DOM and the
      XMLHTTPRequest ActiveX object in IE for Windows. This DOM object allows
      for synchronous requests, that is, you can wait for the request to be
      answered positive and then let the UA close the popup window. Whether
      either approach is a viable solution depends on your client system
      requirements and network environment. Ask Google (Groups) for details.
      [color=blue]
      > The web server I am using is working on a pseudo "cgi" mode called
      > "goforms", it avoids to create a different process for each request.
      > With "goforms", each request is handled by a unique process which is
      > always running.[/color]

      You should really rethink the design of your Web application.


      PointedEars

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: onunload and redirect

        Laurent wrote:[color=blue]
        > I am trying to use the onunload event to know when the user closes a
        > popup by receiving a request on the web server.[/color]

        Unless you can *guarantee* that the user cannot navigate to another
        document within the popup, this is not a viable solution as the onunload
        event will fire then, too. And you cannot guarantee this, unless this
        is for a very restricted Intranet. And IIRC there is a undocumented
        `onclose' event handler in the IE DOM that fires only when a window
        is closed, but the same restriction would apply here.
        [color=blue]
        > I have a main page from where the user opens a popup. What I want is
        > when the user closes the popup, it sends a request to my web server
        > (GoAhead) using the onunload event, then closes the popup.[/color]

        What if client-side scripting is disabled or not even present?
        [color=blue]
        > For the moment, this what i have: when the user closes the popup, I
        > use the onunload event to open a different popup (by this way, I get a
        > request on the web server and I know that the user closes the first
        > popup),[/color]

        You cannot know for sure, unless ... (see above).
        [color=blue]
        > If I try to change the location of the first popup in the onunload
        > event: onunload="docum ent.location='. ...'", it doesn't send a request
        > to the web server when the user closes the popup.[/color]

        `document.locat ion' has been deprecated a long time ago. Use
        `window.locatio n'.
        [color=blue]
        > Is there a way to send a request to the webserver when the user closes
        > the popup without the need to have an extra popup opened and closed ?[/color]

        There is a way to send a request to the Web server if the `unload' event
        fires (or on any other occasion). It is called XML HTTP Request and
        implemented with the XMLHttpRequest object in the Gecko DOM and the
        XMLHTTPRequest ActiveX object in IE for Windows. This DOM object allows
        for synchronous requests, that is, you can wait for the request to be
        answered positive and then let the UA close the popup window. Whether
        either approach is a viable solution depends on your client system
        requirements and network environment. Ask Google (Groups) for details.
        [color=blue]
        > The web server I am using is working on a pseudo "cgi" mode called
        > "goforms", it avoids to create a different process for each request.
        > With "goforms", each request is handled by a unique process which is
        > always running.[/color]

        You should really rethink the design of your Web application.


        PointedEars

        Comment

        Working...