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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Window Close

Status
Not open for further replies.

CP

Programmer
May 28, 2000
2
CA
Hello,<br>Could anyone guide me to a tutorial or provide a code snippet that would do a form submit if a user closes the window prematurely (and is comaptible with IE and Netscape). I've used code that will do an alert when a user clicks to another window which works in both browsers but I'd like to be able to submit form information if the window is closed (prematurely) with the X.<br>Thanks in advance<br>Collin<br>
 
Dear Collin,<br><br>I don't think you will have luck submitting the form since it is already closing along with the browser. In IE you can use the 'window' object to open a new window with your destination url and append all of your form elements to the url, it would look something like this:<br><br>function onBodyUnload(){<br>&nbsp;&nbsp;var surl = &quot;mypage.asp?&quot; +<br>&nbsp;&nbsp;&nbsp;&nbsp;&quot;phone=&quot; + document.form1.txPhone +<br>&nbsp;&nbsp;&nbsp;&nbsp;&quot;&age=&quot; + document.form1.txAge;<br>&nbsp;&nbsp;window.open( surl);<br>}<br><br>You could even do a loop using the form collection to make it more generic.<br><br>You hook this up within the 'body' tag like so:<br><br>&lt;body onunload=&quot;onBodyUnload()&quot;&gt;<br><br>This even works in Nutscrap except that in the version I currently have there is no access to the form elements. This could vary from version to version of Nutscrap, or IE for that matter.<br><br>I apologize for my incomplete information, I only posted this when I saw no other help being offered from anyone else.<br><br>Good luck<br>-pete
 
Thanks for your reply Pete,<br>I tried the script with some success. IE4/5 is okay with it. Netscape 4.03 gives an Illegal URL Method and Netscape 4.07 just ignores it competely. Any other ideas? The script I'm using is below.<br><br>&lt;body onunload=&quot;onBodyUnload()&quot;&gt;<br><br>&lt;script language=&quot;JavaScript&quot;&gt;<br>&lt;!--<br>function onBodyUnload(){<br>var surl&nbsp;&nbsp;= 'mypage.asp?' +<br>&nbsp;&nbsp;&nbsp;&nbsp;'IP=' + document.form1.IP.value +<br>&nbsp;&nbsp;&nbsp;&nbsp;'&Password=' + document.form1.Password.value;<br>&nbsp;window.open( surl);<br>}<br>//--&gt;<br>&lt;/script&gt;<br>Thanks again<br>Collin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top