我开发了一个Firefox附加组件。在当我打电话使用contentScriptFile一个js文件就无法调用main.js,函数(的addEventListener)得到从来没有所谓的firefox插件中的contentScriptListener无法启动相应文件
*** Edit 1 ***
Sorry for missing what I actually need .
In get-text.js I need to send a XMLHttpRequest using GET method . If I attach my javascript in panel.html , then I'm unable to receive the request thereby ,
我在这里附上
main.js整个文件文件
var { ToggleButton } = require('sdk/ui/button/toggle');
var panels = require("sdk/panel");
var self = require("sdk/self");
var data=require("sdk/self").data;
var button = ToggleButton({
id: "my-button",
label: "my button",
icon: {
"16": "./icon.png",
"32": "./icon.png",
"64": "./icon.png"
},
onChange: handleChange
});
var panel = require("sdk/panel").Panel({
width:350,
contentURL: data.url("panel.html"),
contentScriptFile: data.url("get-text.js"),
onHide: handleHide
});
function handleChange(state) {
if (state.checked) {
panel.show({position: button});
}
}
function handleHide() {
button.state('window', {checked: false});
}
GET-text.js文件
(function(){
var init = function() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.hackerearth.com/chrome-extension/events/", true);
xhr.send();
xhr.onreadystatechange = function() {
if(xhr.readyState===4) {
if(xhr.status===200) {
console.log("hello2");
var json = JSON.parse(xhr.responseText);
console.log(json);
} else {
console.log("Status is :"+xhr.status);
}
}
};
};
console.log("function passing");
document.addEventListener('DOMContentLoaded', function() {
console.log("pankaj \t");
init();
});
});
*编辑1 *
你正在使用addon-sdk所以用[标签:firefox-addon-sdk]标记你的东西:)做笔记,因为我看到你做了几次:) – Noitidart 2014-09-01 13:32:59
'panel.show()'出现在任何地方你的插件? – Lori 2014-09-01 15:12:05
@Noitidart因为我不知道,所以我会关心它。 – user1305313 2014-09-01 16:17:32