• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Javascript detection of browser/tab exit

 
Ranch Hand
Posts: 163
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way for Javascript (in Firefox) to detect that the user has exited the browser or tab? To be more specific, exiting by clicking the red "X" in the upper right corner?

I'm aware of the window event 'onbeforeunload', but my situation is a bit more complicated. I have a webpage that displays an embedded pdf. This pdf has several actions that submit its form to the server. So, if I use 'onbeforeunload', any submission through the pdf will trigger this function. I wish to avoid that scenario.

What I'm trying to accomplish is prompting the user with a "You haven't saved your changes" message if they try to leave the page. The pdf has a submit button for "Save" so I do not wish to prompt the user with the previously stated message.

I've been googling left and right and the closest I've come to a solution is here. This didn't work for me. The code specifically mentions microsoft in the comments so I have to assume it's designed for IE.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic