Question

I am new to this Firefox SDK , but what i have understood you can execute content Scripts on Pages.

Here is the Code

MAIN.JS

var tabs = require("sdk/tabs");
var data = require("sdk/self").data;

var sidebar = require("sdk/ui/sidebar").Sidebar({
  id: 'my-sidebar',
  title: 'My sidebar',
  url: data.url("index.html"),
  onReady: function (worker) {

        worker.port.emit('turl',tabs.activeTab.url);
}
});

SIDEBAR.JS

$('#bt1').on('click',function(){

        $('title').textContent;

});

INDEX.HTML

<!DOCTYPE HTML>
<html>
  <body>
        <input type="button" id="bt1" value="Click Me"/>
         <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
        <script src="sidebar.js"></script>
</body>
</html>

But this code tries to find out title of the Sidebar html. I have also tried using contentScriptFile in Main.js but same thing happened

var tabs = require("sdk/tabs");
var data = require("sdk/self").data;

var sidebar = require("sdk/ui/sidebar").Sidebar({
  id: 'my-sidebar',
  title: 'My sidebar',
  url: data.url("index.html"),
  contentScriptFile: [data.url("jquery.min.js"),data.url("sidebar.js")],
  onReady: function (worker) {

        worker.port.emit('turl',tabs.activeTab.url);
}
});

The Jquery code is in the sidebar.js

Still no Results.Please help

Was it helpful?

Solution

There is no contentScriptFile for the Sidebar class.

Try this: copy the jquery library to a local file in the data folder, then refer to it using a relative path. Sidebars can only use 'local' JS, they cannot load scripts from the internet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top