Forum Moderators: open

Message Too Old, No Replies

Automatically submit a form

When the current page is left

         

MatthewHSE

8:17 pm on Aug 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Splitting from this thread [webmasterworld.com], I was wondering if there's any way for javascript to submit a form, comprised of hidden fields, transparently and automatically, when a visitor leaves a webpage either for another page on the same site, or a different site altogether. Basically I want to start a javascript timer that times how long the page is viewed. The value would be used in a hidden form field, so that when the form was submitted, it could be processed and aggregated by some server-side script.

So as not to interfere with normal navigation, the form would need to be submitted completely automatically when the current page was left. It would obviously also need to be entirely transparent to the user.

Is this within the range of Javascript? And if so, how would you handle submitting the form automatically like that?

Thanks,

Matthew

j4mes

8:22 pm on Aug 10, 2005 (gmt 0)

10+ Year Member



I'd have thought a combination of:

document.getElementById('form').submit()

and

onunload=""

would do the trick, although I haven't tested it out.

Something to bear in mind is that some pop-up blockers may unconditionally block onunload since it's rarely used for anything constructive ;-)