biziclop
biziclop

Reputation: 49744

Firefox add-on export variable into page

I've got a Firefox add-on that has a single entry point: a function call that launches an external application.

How do I export that function call into all pages when they're opened (in reality it won't be every page, it will be decided on the page URL), so that pages that are aware of my extension can call it?

Note: there's no need for the add-on to call back into the page or access any of the information on it.

Upvotes: 0

Views: 138

Answers (1)

Christos Papoulas
Christos Papoulas

Reputation: 2568

You can use page-mods. In the include field you can specify the URLs that you want to execute your function, it support table of strings and RegExp. The following example is from the firefox documentation:

var pageMod = require("sdk/page-mod");

pageMod.PageMod({
  include: "*.mozilla.org",
  contentScript: 'console.log("Call your function here!");'
});

Or if you don't want to attach a script into page's window you can use tabs For example:

var tabs = require("sdk/tabs");
tabs.on('ready', function(tab) {
  console.log('tab is loaded', tab.title, tab.url);
  if(tab.url.indexOf("mozilla") != -1) {
    console.log("Call your function here!")
  }
});

Upvotes: 2

Related Questions