Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submitting form data when browser window is closed 1

Status
Not open for further replies.

emozley

Technical User
Jan 14, 2003
769
GB
Hi,

Is it possible to write something so that if a browser window is closed then the contents of any forms are submitted to a database.

If anyone could let me know what sorts of words I should be googling or has a link to an example that would be fantastic.

Thanks very much

Ed
 
There is the onClose event but it has problems: it fires when you change URLs. This could be switching to another URL or closing the window. I haven't found one that will fire only when you close the window but not when you change URLs.
 
Last app i worked on people wanted a similar function. I wasn't assigned with it. You could try onunload.


For some reason ,I forgot why, the person in charge of that functionality chose to alert users user onunload that their data would not be saved if they closed the browser window. Instead of onunload saves he used a timeout that saved form information every few minutes since there forms people filled out were 6 or 7 pages long and took an long time to fill out.

Hope that helps... I'll try to get in contact with the person to see why exactly he implemented the save that way, but for now thats all I can remember.
 
There is an event that I know is supported by IE, window.onbeforeunload I use it all the time when I have a popup window to call a function on the parent page (usually just to clear the window variable which I use for modality. But you can have it do anything really. Even something like this:
Code:
<script type='text/javascript'>
window.onbeforeunload=function() {
  document.forms[0].submit();
}
</script>
This should theoretically cause your form to be saved when the user either closes the browser window, or navigates to a different page. You might want to better control the submit, but other than that - see if this helps you.

Einstein47
“Evil abounds when good men do nothing.“ - Nelson R.
[&#91;]Starbase47.com]
 
This works on all browsers even safari,ie, operah etc... I use it at this very moment. Good luck have fun

<script type='text/javascript'>
window.onunload=function() {
document.formName.submit();
}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top