sending data from client to server on page unload

  • ilc
  • Born
  • Born
  • ilc
  • Posts: 2

Post 3+ Months Ago

Need to send data durig the page view and finally when the page is unloaded
send the rest of the data. Currently it is done like this:

function weHndOnunload()// window.onunload handler
{
...
document.foo.src = weUrl + "/Servlet?" + data;
...
}
...
document.writeln("<IMG NAME='foo' SRC='http://'>");

The problem is that in about 70% of the page views the data is not sent -
the page is unloaded and connection is not established.

Could anybody help? What can be other methods and can they work better (like
<form> and <iframe>)?

Big thanks in advance!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • CazpianXI
  • Proficient
  • Proficient
  • User avatar
  • Posts: 285

Post 3+ Months Ago

I suggest that "onunload" calls a popup window. You could do something like this:

Code: [ Select ]
window2open = weUrl + "/Servlet?" + data;
window.open(window2open, 'submitdata', 'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=1, width=400, height=350, left=50, top=50');
  1. window2open = weUrl + "/Servlet?" + data;
  2. window.open(window2open, 'submitdata', 'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=1, width=400, height=350, left=50, top=50');


This way, if a user leaves your site by closing the browser window, the data will still be submitted. However... if the user has a pop-up killer, the data still won't be submitted. :cry:

Here's an idea: Try submitting the data the way you are presently doing it and submit the data using a popup. That way, you will have better chances of the data being submitted. (But you will have to be able to delete duplicate entries on the server-side)

I hope this answered your question.[/code]
  • ilc
  • Born
  • Born
  • ilc
  • Posts: 2

Post 3+ Months Ago

Good idea, thank you!

I think, the percentage of the visitors having a pop-up killer is much less than current 70% of fails, so it is not a problem and this can really help.

The real problem is a pop-up window itself - it will be annoying to a page visitor. But in any case I will work in this direction, probably doing the window as small as possible.

cwp wrote:
I suggest that "onunload" calls a popup window. You could do something like this:
...
  • CazpianXI
  • Proficient
  • Proficient
  • User avatar
  • Posts: 285

Post 3+ Months Ago

Maybe try this:

Once the pop-up opens and sends the needed data, it closes itself. This way, it will only be open for a second and your users won't get annoyed with it. They might not evern notice it! :D:D

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: wpas and 75 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.