MDN’s new design is in Beta! A sneak peek:

How to Quit a XUL Application

Script can attempt to quit a XUL application, or force the application to quit, using the nsIAppStartup interface.

function quit (aForceQuit)
  var appStartup = Components.classes[';1'].

  // eAttemptQuit will try to close each XUL window, but the XUL window can cancel the quit
  // process if there is unsaved data. eForceQuit will quit no matter what.
  var quitSeverity = aForceQuit ? Components.interfaces.nsIAppStartup.eForceQuit :

Calling this function if there is an uncaught exception, to force the application to quit:

try {
catch (e) {

The "Quit" menuitem should typically prompt the user if there is unsaved data:

<menuitem label="Quit" oncommand="quit(false);"/>

Document Tags and Contributors

 Contributors to this page: teoli, Mgjbot, bsmedberg, StM
 Last updated by: Mgjbot,