firefox javascript window.open _self

时间:2013-10-04 09:15:54

标签: javascript firefox firefox-addon

我的问题是:
当我使用时:

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'");

2 个答案:

答案 0 :(得分:2)

gBrowser.loadURI('http://www.example.com');

正常运作。

答案 1 :(得分:0)

gBrowser.loadURI将页面加载到我认为的选定标签中。

如果你想打开一个新窗口,你必须这样做:

var url = Cc['@mozilla.org/supports-string;1'].createInstance(Ci.nsISupportsString);
url.data = 'http://www.bing.com/';
Services.ww.openWindow(null, 'chrome://browser/content/browser.xul', '_blank', 'chrome,all', url);
相关问题