我正在为 Fennec 开发一个简单的扩展,它必须向每个加载的页面添加特殊的 HTML 元素。我创建了这个简单的 overlay.js:
var MyAddon = {
onLoad: function(aEvent){
var appcontent = document.getElementById("appcontent"); // Firefox
if (!appcontent) {
appcontent = document.getElementById("browsers"); // Fennec
}
if (appcontent) {
appcontent.addEventListener("DOMContentLoaded", MyAddon.onDocumentLoad, true);
}
},
onUnLoad: function(aEvent){
var appcontent = document.getElementById("appcontent"); // Firefox
if (!appcontent) {
appcontent = document.getElementById("browsers"); // Fennec
}
if (appcontent) {
appcontent.removeEventListener("DOMContentLoaded", MyAddon.onDocumentLoad, true);
}
},
onUIReady: function(aEvent){
},
onUIReadyDelayed: function(aEvent) {
},
onDocumentLoad: function(aEvent) {
alert("OK");
}
};
window.addEventListener("load", MyAddon.onLoad, false);
window.addEventListener("unload", MyAddon.onUnLoad, false);
window.addEventListener("UIReady", MyAddon.onUIReady, false);
window.addEventListener("UIReadyDelayed", MyAddon.onUIReadyDelayed, false);
问题是警报仅在浏览器启动时显示一次,我希望它显示在每个加载的页面上。我究竟做错了什么?
Fennec 版本:4.0b5(Windows 桌面版测试)
谢谢!