wood burning stoves*
The moose likes HTML, CSS and JavaScript and the fly likes onUnload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "onUnload" Watch "onUnload" New topic
Author

onUnload

Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
hi all,

Please have a look at my html


if i click on the 'submit' button im getting the alert message "submit me" but if i close the window im not getting "submit me" message but im getting "gonna submit form".. why is that ?

Thanks,
Rajeev
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Clicking your submit button will submit the form, meaning it will submit it to whatever is in the action attribute of your form tag. So your action attribute calls the JavaScript the pops up the alert box with 'submit me' in it.

When you close the window, the onUnload attribute of the body tag gets called, and your onUnload attribute calls the JavaScript funtion callme() which pops up an alert box with the text "gonna submit form" in it.
Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
hey Stephen , thanks for the reply !!

Just to figure out watz happening there, i invoked a servlet on form submit and i found its too inconsistent. Sometimes when i close the browser window tat servelt is getting invoked sometimes its not !!

What i really need is , i want to a servlet to be executed whenever i close the window but when i dont want the servlet to execute if i refresh the window.. any help on this is highly appretiated.. i have spend a lot of time on this.. i dont trust calling js funtion onUnload() and checking clientX and clientY position, it sometimes works properly on IE + Win XP but the same wasnt working on IE + Win 2000.. any tips or tricks ?

Thanks,
Rajeev
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
There is no real way to determine if the window is closing, going to another page, or being refreshed.

Eric
 
jQuery in Action, 2nd edition
 
subject: onUnload
 
Similar Threads
on button click value is not getting
form validator to check for alphabets in a text field
JSP in Javascript
Prevent Duplicate Logins
Opening a child window