2013-10-04 39 views
1

我的問題是:
當我使用:Firefox的JavaScript的window.open _self

window.open("example.com","_self"); 

self.open("example.com"); 

window.location.href="example.com"; 

火狐刪除所有菜單,按鈕,窗口窗口最小化按鈕,一切。此外上下文菜單停止工作,但網站打開罰款除了這混亂,這一切都毀了。

那麼如何解決這個問題呢?

編輯: 我使用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'"); 
+1

它會直接將您重定向到「example.com」這就是爲什麼它沒有顯示你的菜單和all..if你想在你的頁面的特定位置打開網址,你可以使用框架或種類在特定的地方打開網址。 –

+1

你正在使用哪個版本的FF?我[無法重現](http://jsfiddle.net/Qeagx/)這與FF24。 – Teemu

+0

我更新了第一篇文章。 – user2838984

回答

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

正常工作。

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); 
+1

OP不想打開一個新窗口(因此爲什麼OP的原始調用是通過'_self'傳遞的)。 – Brian

+0

啊,我在那裏學到了東西,很好。 Thx男人。 – Noitidart