我正在编写一个 Firefox 附加组件,并且我正在使用高级 Firefox 附加组件 SDK API。
我的加载项会打开一个新窗口,并在该窗口中打开多个选项卡。
如何让这个新窗口在后台打开?我不希望它的打开打断用户对事件窗口的关注。
打开标签页时,有一个 inBackground 选项可用于此目的。
我到处搜索了 windows 模块文档,但在创建新窗口时找不到类似的选项!
如何在后台打开这个新窗口?
如果 Mozilla 禁止我这样做,有没有一种方法可以让我在新窗口打开后迅速将其推送到后台,从而将干扰降到最低?
最佳答案
不允许。非常好。我认为使用 alwaysLowered
的功能选项来做到这一点。
可在此处找到完整的功能列表:https://developer.mozilla.org/en-US/docs/Web/API/window.open#Position_and_size_features
var sa = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
var wuri = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
wuri.data = 'about:blank';
sa.AppendElement(wuri);
let features = "chrome,dialog=no,alwaysLowered";
var wantTabs = false;
if (wantTabs) {
features += ',all';
}
/*var sDOMWin = aTab.ownerGlobal; //source DOMWindow*/
if (PrivateBrowsingUtils.permanentPrivateBrowsing/* || PrivateBrowsingUtils.isWindowPrivate(sDOMWin)*/) {
features += ",private";
} else {
features += ",non-private";
}
var XULWindow = Services.ww.openWindow(null, 'chrome://browser/content/browser.xul', null, features, sa);
您可以将此代码标记到末尾,以便在 XULWindow
加载后执行某些操作:
XULWindow.addEventListener('load', function() {
//can lower or raise the window z-index here
var DOMWindow = XULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
DOMWindow.gBrowser.selectedTab.linkedBrowser.webNavigation.stop(Ci.nsIWebNavigation.STOP_ALL);
}, false);
关于javascript - 使用 Firefox 附加组件 SDK 打开后台窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27203970/