Skip to content Skip to sidebar Skip to footer

Firefox Addon Builder Preferences-services Not Working For Me--why?

I am trying to make a button in the Firefox Add-on Builder that will change the URL that the searchbar uses. To change the URL, I have a panel that shows when the button is clicked

Solution 1:

The HTML pages loaded by your extension don't have any special privileges - they are just like regular web pages. In particular, the function require() isn't defined in this context. What you need to do is to load a content script into the panel because a content script can communicate back to the extension. This content script could look like this:

// Add event listener in the content script, the page cannot "see" content script// functionsvar buttons = document.getElementsByClassName("searchButton");
for (var i = 0; i < buttons.length; i++)
  buttons[i].addEventListener("click", changekeywordurl, false);

// Send a message to the extension if a button is clickedfunctionchangekeywordurl(event)
{
  var button = event.target;
  self.postMessage(button.getAttribute("_keywordURL"));
}

And the button in the page would look like this:

<button_keywordURL="http://search.yahoo.com/search?p="></button>

Then your extension can listen to messages from the content script and use the necessary SDK modules.

Post a Comment for "Firefox Addon Builder Preferences-services Not Working For Me--why?"