Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Wait till image is loaded from "onbeforeunload" handler?

Reply
Thread Tools

Wait till image is loaded from "onbeforeunload" handler?

 
 
Robert Oschler
Guest
Posts: n/a
 
      08-30-2003
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

--

Robert Oschler
"Let the web hear you, add your voice to your web site in minutes!"
-- http://audiodirect.spiderchase.com/
(For a limited time, free voiceover with every sign-up, use this link
instead)
-- http://audio.spiderchase.com/
(A song - are you blue?)
-- http://bluedreams.spiderchase.com/


 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      08-30-2003
"Robert Oschler" <no_replies@fake_email_address.invalid> wrote in
message news:nU24b.20353$ et...
>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?


I doubt that your stated desire can be realistically achieved over the
Internet as there is nothing to guarantee that the user is connected at
the point - onbeforeunload - or - onunload - events are triggered (and
lots of other reasons on top). But you are apparently writing
exclusively for IE so your application may not be for the Internet. If
not you should say so.

However, It would probably be best to:
1. Show the code that is not working (otherwise obvious
improvements/suggestions cannot be made.
2. Explain why you want to do this. If it is something that needs to be
100% reliable then attempting it using JavaScript is probably trying to
solve the wrong problem.

Richard.


 
Reply With Quote
 
 
 
 
Grant Wagner
Guest
Posts: n/a
 
      09-03-2003
Robert Oschler wrote:

> 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


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 <>

* 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Let thread wait till memory is available senges Java 3 05-10-2007 01:59 PM
I Better wait till version 1 Colonel Blip Firefox 7 07-12-2004 10:37 PM
How to make "fork/wait" to WAIT longer? Huey C Programming 1 03-01-2004 02:01 PM
java -verbose doesn't show "loaded from" for classes loaded from custom jars in the classpath Udo Corban Java 0 01-23-2004 09:32 AM
Re: how to programatically give assembly loaded from network the same trust as those loaded from local host? Marcelo Birnbach [MS] ASP .Net 0 06-27-2003 11:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57