• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to check browser close event?

 
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to prompt user with Whether he wants to Save changes if he clicks X on browser etc.

How to do that.

I tried <body onunload="method()">

but it is called everytime I perform operation on page. Say I click on any button method is called.

I only want to call method when user closes browser etc.
[ November 07, 2006: Message edited by: Santana Iyer ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a tricky problem, and you're not the first to encounter it. Try Googling "javascript detect window close" as I did, and you'll see some interesting approaches to solving it. This link looks the most promising to me, although I don't know if it's a cross-browser solution.

Also, I'm moving this to the HTML/JavaScript forum, since that's really where it belongs.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic