473,287 Members | 3,319 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Wait till image is loaded from "onbeforeunload" handler?

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/
Jul 20 '05 #1
2 6713
"Robert Oschler" <no_replies@fake_email_address.invalid> wrote in
message news:nU*********************@news2.news.adelphia.n 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.
Jul 20 '05 #2
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 <gw*****@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
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robert Oschler | last post by:
I've successfully attached to the "onclick" and several other events using AttachEvent(). But when I try to attach to the "onbeforeunload" event it doesn't work (the handler I've assigned is never...
3
by: Gordon Mohr | last post by:
I'd like to set up a bit of javascript to be run when other javascript loads a new page via something like { top.window.location.href = newLocation }, and have access to the new value. (For...
2
by: M B HONG 20 | last post by:
Hi all - I am developing an ASP.NET (C#) application and need some help. I wish to call a server-side function (in the code-behind "file.aspx.cs") upon a user clicking on the "X" to close the...
6
by: sowencheung | last post by:
I have the following code in the event onbeforeunload if ( typeof executingPostBack != 'undefined' && !executingPostBack ) event.returnValue = ""Warning: Modified data has not been saved.""; ...
0
by: Jonathan | last post by:
Hi Everyone, I have a problem which I've been able to reproduce with a nice and small test ASP.NET web application. The page sets the window.onbeforeunload event so that we will get an Ok/Cancel...
5
by: nic829 | last post by:
I am trying to write a code such that when user close the browser or netvigate to other page, a message box will show up. <SCRIPT> function closeIt() { event.returnValue =...
4
hemantbasva
by: hemantbasva | last post by:
We have designed an aspx page having five ajax tab in it. the data of first four are designed on page whereas for the fifth tab it renders a user control named MYDOMAIN. in the tab container's even...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.