2013-07-09 23 views
2

我想創建一個bootstrapped firefox擴展來獲取當前標籤的URL和標題。問題是,我想檢查一下標籤網址在其url中是否包含「about:」字樣。我建議的解決方案是使用瀏覽器本地string.substr()javascript函數來檢查require(「sdk/tabs」).activeTab.url「。是否有任何可能性使用瀏覽器原生javasript小部件或ToolbarButton onClick方法上的函數?獲取激活瀏覽器選項卡屬性在Firefox插件建設者

exports.main = function(options) { 

    var base64 = require("sdk/base64"); 

    var panel = require("sdk/panel").Panel({ 
     width: 700, 
     height: 470, 
     onHide: function() 
     { 
     panel.contentURL = "about:blank"; 
     } 
    }); 

    var tbb = require("toolbarbutton").ToolbarButton({ 
     id: "extension-tbb-id", 
     label: "IFShare+", 
     image: "https://www.fasdfasd.es/factory/templates/templateforidkreader/favicon.ico", 
     panel: panel, 
     onClick: function() 
     { 
     windowPanel = require("sdk/tabs").activeTab; 

     title = windowPanel.title; 
     url = windowPanel.url; 
     // Is any posibility to do something like that ???? 
     contentScript: "if("+url+".substring(0,5)=='about:'){" 
     { 
      url=''; 
      title=''; 
     } 
     contentScript: "}" 

     this.panel.contentURL = "https://www.fasdfasdf.es/factory/index2.php?option=com_idkreader&view=shareplus&task=window&Itemid=0&url="+base64.encode(url, "utf-8")+'&title='+base64.encode(title, "utf-8")+'&ref=ext';  
     }, 

    }); 


    // move the toolbar button to the navigation bar 
    if ("install" == options.loadReason) { 
    tbb.moveTo({toolbarID: "nav-bar"}); 
    } 
} 

回答

0

我對你要完成什麼樣的細節尚不完全清楚,但我想你靠近。

要回答這一問題問,沒有你不能訪問你可以做的最好的是使用內容腳本消息提到的the page-mod documentation

但是,爲了完成你想要的東西,你不需要這樣做。你可以做你想做的在onclick函數本身,像這樣

function onClick() 
    { 
    windowPanel = require("sdk/tabs").activeTab; 

    title = windowPanel.title; 
    url = windowPanel.url; 

    if(url.substring(0,5)=='about:'){ 
    { 
     url=''; 
     title=''; 
    } else { 
     //You can insert any content script stuff you want here 
    } 
    this.panel.contentURL = "https://www.fasdfasdf.es/factory/index2.php?option=com_idkreader&view=shareplus&task=window&Itemid=0&url="+base64.encode(url, "utf-8")+'&title='+base64.encode(title, "utf-8")+'&ref=ext';  
    } 

如果您優化的問題一點,我會很高興地改進我的答案。

+0

我很感激你的幫助,它真的很有用。或多或少你已經回答了我的關注。現在我更加了解插件創建和JavaScript。 – user2563541

相關問題