【问题标题】:Firefox extension panel doesn't execute html codeFirefox 扩展面板不执行 html 代码
【发布时间】:2014-11-04 06:32:59
【问题描述】:

您好,我正在尝试在 Firefox 扩展中创建一个面板,其中 html 代码由 javascript 代码动态插入。这是代码:

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();
});

但是 html 代码没有完全执行....面板构建良好但 html 代码没有调用“get-text.js”脚本。使用外部文件 html 和 "contentURL: data.url("panel.html")" 代码扩展运行良好。你有什么解决办法吗?非常感谢。

【问题讨论】:

    标签: javascript html firefox firefox-addon firefox-addon-sdk


    【解决方案1】:

    我解决了.....问题解决了在面板代码中插入这一行:

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

    【讨论】:

    • 你可以(而且应该!)接受你自己的答案,如果这就是你解决问题的方式。
    • 我试图接受答案,但我不能,因为我必须等待 2 天
    猜你喜欢
    • 1970-01-01
    • 2011-05-12
    • 1970-01-01
    • 2013-06-29
    • 2011-01-21
    • 2012-12-24
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    相关资源
    最近更新 更多