Robert Oschler wrote:
[color=blue]
> I have a web page where I want to make sure that an image HTTP request is
> successfully made before the page unloads. The request is made by setting
> the image element's SRC property to the desired URL.
>
> When I put the SRC property change in either an "onbeforeunload" or
> "onunload" event handler, the HTTP request is not received by our server as
> much as 75% of the time.
>
> I thought of setting a flag using an "onload" handler for the image element,
> to tell me when the HTTP request had completed, and then waiting for that
> flag in the "onbeforeunload" or "onunload" document event handlers. But
> that doesn't work because Internet Explorer only processes one event at a
> time.
>
> Can anyone think of a reliable strategy to make sure that an HTTP request is
> definitely sent off before leaving the page?
>
> thx[/color]
No, you can't guarantee anything done with JavaScript executes at any time. And
relying on it to close database connections or log the user off or whatever you
are relying on it for is a flawed design.
Design the server-side processes to handle timed out sessions correctly and
rationally and then you don't need to rely on client-side technologies to do
what they cannot do.
--
| Grant Wagner <gwagner@agricoreunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
*
http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
*
http://www.mozilla.org/docs/web-deve...upgrade_2.html