您好我正在尝试在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代码没有调用&#34; get-text.js&#34;脚本。使用外部文件html和&#34; contentURL:data.url(&#34; panel.html&#34;)&#34;编码扩展工作很好。你有什么解决方案吗?非常感谢。
答案 0 :(得分:3)
我解决了......问题解决了在面板代码中插入这一行:
contentScriptFile: data.url("get-text.js"),