0
votes

Hi I'm trying to create a Panel in a Firefox extension in which the html code is dinamically inserted by javascript code. This is the code:

var { ToggleButton } = require('sdk/ui/button/toggle');
var panels = require("sdk/panel");
var HTMLPage = '<html><head><link href="panel-style.css" type="text/css" rel="stylesheet"></head>'
    + '<body><form>What is your name?: <input id="user-real-name" placeholder="Insert here your name"/><br />'
    + '<input type="button" value="Submit" id="submit-btn"/></form><script src="get-text.js"></script>'
    + '</body></html>';


var button = ToggleButton({
   id: "button",
   label: "tmp Button",
   icon: {
        "16": "./icon-16.png",
        "32": "./icon-32.png",
        "64": "./icon-64.png"
   },
onChange: handleChange
});
var panel = panels.Panel({
   width: 200,
   height: 100,
   contentURL: "data:text/html," + HTMLPage,
   onHide: handleHide
});
function handleChange(state) {
   if (state.checked) {
       panel.show({
          position: button
       });
   }
}
function handleHide() {
   button.state('window', {checked: false});
}
panel.on("show", function() {
   panel.port.emit("show");
});
panel.port.on("text-entered", function (text) {
   console.log(text);
   panel.hide();
});

But html code is not completely executed....the panel is built well but the html code doesn't call the "get-text.js" script. Using an external file html and "contentURL: data.url("panel.html")" code the extension work well. Do you have any solution? Thanks a lot.

1

1 Answers

3
votes

I solved.....the problem is solved inserting this line in panel's code:

contentScriptFile: data.url("get-text.js"),