【发布时间】: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