簡體   English   中英

如何從firefox擴展名重啟Mozila Firefox瀏覽器

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM