• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

onUnload

 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no real way to determine if the window is closing, going to another page, or being refreshed.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic