Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Control browser close event

 
Gavi Raaghav
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the user tries to close the browser i need to present him with a confirm dialog box of OK/Cancel. Clicking on OK will close the browser and clicking on Cancel will keep the user on the same screen.
How to achieve this using Javascript.
onUnload() calls the function but whatever be the user action the browser closes.
Any pointers will be highly appreciated.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
only way to do it is IE only and that is the onbeforeunload event handler. There is not other way to capture the close, you have to realize that the back button, refresh button, links, and closing the browser fire the same event, hence why it basically is impossible to determine what happened.

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