Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

How to Quit a XUL Application

nsIAppStartup インターフェイスを用いて Script から XUL アプリケーションを終了させたり、アプリケーションを強制終了させる事が出来ます。

<script>
function quit (aForceQuit)
{
  var appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1'].
    getService(Components.interfaces.nsIAppStartup);

  // eAttemptQuit は XUL をそれぞれ閉じていくよう試みますが、セーブしていないデータがある場合 
  // XUL window は終了のプロセスをキャンセルする事ができます。eForceQuit は何があっても終了するでしょう。
  var quitSeverity = aForceQuit ? Components.interfaces.nsIAppStartup.eForceQuit :
                                  Components.interfaces.nsIAppStartup.eAttemptQuit;
  appStartup.quit(quitSeverity);
}
</script>

捕捉されない例外があったときにこの関数を呼べば、アプリケーションは強制的に終了します:

<script>
try {
  doSomething();
}
catch (e) {
  quit(true);
}
</script>

この "Quit" menuitem は一般的にセーブしていないデータがあればユーザにプロンプトを表示するでしょう:

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

ドキュメントのタグと貢献者

タグ: 
 このページの貢献者: Btm
 最終更新者: Btm,