onbeforeunload + server notification

  • Thread starter Salvatore Sanfilippo
  • Start date
S

Salvatore Sanfilippo

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

scripts.contact

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

Salvatore Sanfilippo

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
 

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

Forum statistics

Threads
473,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top