Can´t ensure submit is really executed

B

besbello

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

Christopher J. Hahn

besbello said:
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. ;)
 
B

besbello

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 said:
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. ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top