469,623 Members | 1,535 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

Canīt ensure submit is really executed

Hi all,
I want to submit a form when the user closes the browser, to keep a
count of the number of users accesing my application at each moment. To
do this, I use the onbeforeunload() event, that calls a function when I
call form.submit() method. The problem is that I have to put an
'alert()' after this line, if I remove the 'alert()' line, things
donīt work. The submit() method seems to return before the form is
really submitted, and the browser get closed, so the form is never
really submitted. I donīt want to have this annoying 'alert()'. Does
anybody know another way to ensure submit really executes before
browser get closed?
Thanks a lot.

Jul 23 '05 #1
3 1252

Why not submitting on load ?

Jul 23 '05 #2
besbello wrote:
Hi all,
I want to submit a form when the user closes the browser, to keep a
count of the number of users accesing my application at each moment. To
do this, I use the onbeforeunload() event, that calls a function when I
call form.submit() method. The problem is that I have to put an
'alert()' after this line, if I remove the 'alert()' line, things
donīt work. The submit() method seems to return before the form is
really submitted, and the browser get closed, so the form is never
really submitted. I donīt want to have this annoying 'alert()'. Does
anybody know another way to ensure submit really executes before
browser get closed?
Thanks a lot.


Just a suggestion: have you tried POSTing synchronously using an
XMLHTTPRequest? It seems like the most reliable JS-based option,
disregarding backward (and some sideways) compatibility.

And a note... disregarding backward or sideways compatbility is not
something I recommend. Regardless of the direction you choose to go,
have a backup such as the auto-expiring sessions database noted below.

There is no 100% reliable way to do what you're looking for, JS or no.
Some people open popups that do the job, but they are often blocked or
closed before they can get the job done, and they're irritating as
[snipped]. Some people use session databases where sessions are
considered expired after X minutes/seconds, but this is highly
inaccurate [best used as a fall-back] and might involve a lot of extra
server-side work. You might combine this with a periodic automatic
refresh of some kind (fifty ways to skin that cat) to keep sessions
alive.

Other software might be more reliable, but still run into
incompatibility and accuracy issues. A Flash or Java applet that keeps
the server aware of its state would work. Of course, the client machine
would have to have Flash or JRE installed and security settings
configured appropriately to allow them to communicate with your server
(i.e. via a TCP socket/connection).

For more information on XMLHTTPRequest, search the group archives at
Google and the group FAQ. Lots of great info.

For more info on Flash and Java... well, I wouldn't know. Go somewhere
else. ;)

Jul 23 '05 #3
Hi again,
Larsens : I haven`t explained it well. Yes, I increment de number of
users when I load the page, but I need to decrement it not only if the
user navigates to another page in my application (easy), but also when
he/she closes the browser or goes to a external page.
Christopher J. Hahn: Thanks a lot for your answer. Iīll take a look at
that.

Any other suggestion would be very appreciated

Christopher J. Hahn ha escrito:
besbello wrote:
Hi all,
I want to submit a form when the user closes the browser, to keep a
count of the number of users accesing my application at each moment. To
do this, I use the onbeforeunload() event, that calls a function when I
call form.submit() method. The problem is that I have to put an
'alert()' after this line, if I remove the 'alert()' line, things
donīt work. The submit() method seems to return before the form is
really submitted, and the browser get closed, so the form is never
really submitted. I donīt want to have this annoying 'alert()'. Does
anybody know another way to ensure submit really executes before
browser get closed?
Thanks a lot.


Just a suggestion: have you tried POSTing synchronously using an
XMLHTTPRequest? It seems like the most reliable JS-based option,
disregarding backward (and some sideways) compatibility.

And a note... disregarding backward or sideways compatbility is not
something I recommend. Regardless of the direction you choose to go,
have a backup such as the auto-expiring sessions database noted below.

There is no 100% reliable way to do what you're looking for, JS or no.
Some people open popups that do the job, but they are often blocked or
closed before they can get the job done, and they're irritating as
[snipped]. Some people use session databases where sessions are
considered expired after X minutes/seconds, but this is highly
inaccurate [best used as a fall-back] and might involve a lot of extra
server-side work. You might combine this with a periodic automatic
refresh of some kind (fifty ways to skin that cat) to keep sessions
alive.

Other software might be more reliable, but still run into
incompatibility and accuracy issues. A Flash or Java applet that keeps
the server aware of its state would work. Of course, the client machine
would have to have Flash or JRE installed and security settings
configured appropriately to allow them to communicate with your server
(i.e. via a TCP socket/connection).

For more information on XMLHTTPRequest, search the group archives at
Google and the group FAQ. Lots of great info.

For more info on Flash and Java... well, I wouldn't know. Go somewhere
else. ;)


Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by a10392 | last post: by
reply views Thread by Fabio R. | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.