• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to override the window.close() event

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I close the browser window,I want to confirm the does the user really wants to close the browser window by calling the window.confirm() method. And when cancel button is pressed I want that the browser window does not close. I am calling window.confirm method when the onunload method is called. But this happens after the browser window gets closed so how do I handle this . Suggest some way.
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should be something like this...you can also trigger onbeforeunload in IE. Closing with the little "x" may pose another situation...
<script language="javascript">
function makeSure(){
if(confirm("are you sure you want to close?")){
window.close();
}
}
</script>
<form>
<input type="button" onclick="makeSure();" value="Close Window">
</form>
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
unfortunately, if the user closes the browser with something other than that button (like clicking the little 'x' in the application window) you're out of luck. The onunload event will fire, but I don't think there's anything you can do can prevent the browser from closing . . .
 
I found a beautiful pie. And a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic