我開發了一個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