2013-02-21 74 views
1

我有https://addons.mozilla.org/en-US/developers/builder(附加組件製造商)工作,我嘗試做以下事情:附加組件SDK是Mozilla Firefox currentURI

1.How改變currentURI地址?方法setTabURL()不適合,因爲立即打開該URL。

雖然找到了出路:

tab.attach ({ 
    contentScript: "history.pushState ('','', '" + tab.url + "');", 
}); 

2.How得到了在地址欄中輸入的URL地址?方法getTabURL()只顯示已結算的地址。

3.如何將文本添加到工具欄中的圖標?我在這裏使用它:https://builder.addons.mozilla.org/package/166563/

+0

好吧,我解決了第一和第二個問題。謝謝:http://stackoverflow.com/questions/10363708/firefox-sdk-keydown-keyup-events(check element and event.target.value = val) – lampa 2013-02-21 20:18:17

回答

6

要訪問URL欄和它的相關值,你必須挖掘一下瀏覽器chrome。

該代碼段將獲取/設置爲當前聚焦的瀏覽器窗口的地址欄值:

var wuntils = require('sdk/window/utils'); 
var document = wuntils.getMostRecentBrowserWindow().document; 
// log the current URL bar value 
console.log(document.getElementById("urlbar").value); 
// change the current URL bar value (this won't change the page) 
document.getElementById("urlbar").value = "Thrift Shop"; 
+0

好的,謝謝!關於第三個問題,你什麼都知道? – lampa 2013-02-21 21:57:26

+0

是的,這是一個CSS的東西。瀏覽器CSS通常將工具欄按鈕標籤設置爲'display:none'。你需要添加自己的CSS來覆蓋規則。只要做一些像'#MyAddon .toolbarbutton-text {display:block; }'使用這段代碼將數據目錄中的樣式表加載到瀏覽器中https://gist.github.com/clarkbw/4999903 – 2013-02-21 22:06:55

+0

!!!非常感謝你! – lampa 2013-02-22 07:15:37

相關問題