2013-02-21 76 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

相关问题