2
votes

I am trying to create a bootstrapped firefox extension to obtain current tabs url and title. The issue is that I want to check when the tab url has the word "about:" in its url. The solution that I propose is to check the require("sdk/tabs").activeTab.url" using the browsers native string.substr() javascript function. Is any posibility to use browsers native javasript functions on widget or ToolbarButton onClick method?

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"});
   }
}
1

1 Answers

0
votes

I'm not entirely clear on the details of what you're trying to accomplish, but I think you're close.

To answer the question as asked, no you can't access variables from within a content script. The best you can do is use content script messaging a mentioned in the page-mod documentation.

However, to accomplish what you want, you don't need to do this. You can just do what you want in the onClick function itself, like so

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';      
  }

If you refine your question a bit, I will be happy to refine my answer.