I'm developing a firefox extension and i want to be able to close firefox window itself (without any confirm). For example, I want to close firefox window if a specific URL has been loaded. Open/close tab is easy with gBrowser, what about closing firefox window?
Thank you
Components
.classes['@mozilla.org/toolkit/app-startup;1']
.getService(Components.interfaces.nsIAppStartup)
.quit(Components.interfaces.nsIAppStartup.eAttemptQuit)
var boot = Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(Components.interfaces.nsIAppStartup);
boot.quit(Components.interfaces.nsIAppStartup.eForceQuit|Components.interfaces.nsIAppStartup.eRestart);
eConsiderQuit : Attempt to quit if all windows are closed.
eAttemptQuit : Try to close all windows, then quit if successful.
eForceQuit : Force all windows to close, then quit.
eRestart : Restart the application after quitting. The application will be restarted with the same profile and an empty command line.
It sounds obvious but you use window.close()
to close a XUL window. As to the warning, the best way is probably to temporarily switch the browser.tabs.warnOnClose
preference to false
. Something like this should work:
Components.utils.import("resource://gre/modules/Services.jsm");
var prefName = "browser.tabs.warnOnClose";
var restorePref = false;
if (Services.prefs.getBoolPref(prefName))
{
Services.prefs.setBoolPref(prefName, false);
restorePref = true;
}
window.close();
if (restorePref)
Services.prefs.setBoolPref(prefName, true);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.