Connecting Tech Pros Worldwide Forums | Help | Site Map

onbeforeunload + server notification

Salvatore Sanfilippo
Guest
 
Posts: n/a
#1: May 17 '07
Hello,

I need to notify the server that the user closed a window.
In order to do so I tried to use the onbeforeunload event
to create an image object having as url the GET request
I need to perform to hint a PHP file server-side.

With firefox this is not working, I guess the page is flushed
away before the browser can load the image.

Is there some alternative solution not involving popups
or other nasty tricks?

Thanks in advance

Regards,
Salvatore

p.s. syncronous ajax is not an option since the server
is in a different domani.


scripts.contact
Guest
 
Posts: n/a
#2: May 17 '07

re: onbeforeunload + server notification


On May 17, 9:20 am, Salvatore Sanfilippo <anti...@gmail.comwrote:
Quote:
Hello,
>
I need to notify the server that the user closed a window.
In order to do so I tried to use the onbeforeunload event
to create an image object having as url the GET request
I need to perform to hint a PHP file server-side.
>
With firefox this is not working, I guess the page is flushed
away before the browser can load the image.
>
try onunload event -
note that opera fires the onunload only when you navigate away from
webpage or refresh the page but not when you close the tab/window.


Salvatore Sanfilippo
Guest
 
Posts: n/a
#3: May 18 '07

re: onbeforeunload + server notification


On May 18, 12:09 am, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
Quote:
try onunload event -
note that opera fires the onunload only when you navigate away from
webpage or refresh the page but not when you close the tab/window.
This is working much better while not 100% reliable.
I also found that creating the image object in the body
via body.innerHTML += "< img src..." for some reason
improve the reliability.

Thank you for the help.

Regards,
Salvatore

Closed Thread