[英]How to restart Mozila Firefox browser from firefox extension
我正在创建一个Firefox扩展。 从扩展程序的js文件中满足一定条件后,我必须重新启动firefox。 那么,如何通过扩展javascript重新启动firefox浏览器? 提前致谢。
使用此代码 :
function restart() {
let canceled = Cc["@mozilla.org/supports-PRBool;1"]
.createInstance(Ci.nsISupportsPRBool);
Services.obs.notifyObservers(canceled, "quit-application-requested", "restart");
if (canceled.data) return false; // somebody canceled our quit request
// disable fastload cache?
if (getPref("disable_fastload")) Services.appinfo.invalidateCachesOnRestart();
// restart
Cc['@mozilla.org/toolkit/app-startup;1'].getService(Ci.nsIAppStartup)
.quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart);
return true;
}
下面的代码将调用已经存在的Mozilla重新启动命令(确保完成所有适当的清理)。
这将在您有权访问浏览器窗口元素的上下文中(即从您打开的对话框窗口(例如,选项对话框))起作用:
window.opener.content.document.getElementById('cmd_restartApp').doCommand();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.