我的问题是:
当我使用:
window.open("example.com","_self");
或者
self.open("example.com");
或者
window.location.href="example.com";
Firefox 删除所有菜单、按钮、窗口的窗口最小化按钮,一切。上下文菜单也停止工作,但网站打开正常,除了这种混乱,这会破坏一切。
那么如何解决这个问题呢?
编辑: 我正在使用 FF22,全新安装。看起来这不是一个简单的案例,所以我把整个代码放在这里,它是稍微编辑的插件,用于从上下文菜单创建新选项卡:
let _ = require("l10n").get;
let winUtils = require("window-utils");
let { isBrowser } = require("api-utils/window/utils");
var delegate = {
onTrack: function (window) {
if (isBrowser(window) ){
let menu = window.document.getElementById("tabContextMenu");
let newtab = window.document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul","menuitem");
newtab.setAttribute("id", "contexttab-newtab");
newtab.setAttribute("label", _("newtab_string"));
newtab.setAttribute("accesskey", _("newtabaccesskey_string"));
newtab.setAttribute("oncommand", "window.location.href='http://www.example.com'");
menu.insertBefore(newtab, menu.firstChild);
} // End isBrowser
} // End ontrack
} // End delegate function
let tracker = new winUtils.WindowTracker(delegate);
// code to remove the menuitem when extension is disabled for satisfy requirement on AMO for pass a full review
// On uninstall the menuitem is not removed, see: https://bugzilla.mozilla.org/show_bug.cgi?id=627432
exports.onUnload = function(reason) {
var unloader = {
onTrack: function (window) {
if (isBrowser(window) ){
let menu = window.document.getElementById("tabContextMenu");
let newtab = window.document.getElementById("contexttab-newtab");
menu.removeChild(newtab);
}
}
}; // End unloader function
let remover = new winUtils.WindowTracker(unloader);
}
这是我编辑的唯一一行:
newtab.setAttribute("oncommand", "window.location.href='http://www.example.com'");