[英]Firefox extension: how to get a script to run from a load overlay
我已经加载了扩展程序,并且能够使状态显示在底部。 我试图将以下代码添加到chrome.manifest文件中:
chrome.manifest:
content sample chrome/content/
overlay chrome://browser/content/browser.xul chrome://sample/content/sample.xul
然后在sample.xul中,我有以下内容:
sample.xul:
<?xml version="1.0"?>
<overlay id="sample"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<statusbar id="status-bar" hidden="false">
<statusbarpanel id="my-panel" label="Hello, World v2" />
</statusbar>
<menubar id="main-menubar">
<menu label="Jeff" insertbefore="tools-menu">
<menupopup>
<menuitem label="About"/>
</menupopup>
</menu>
</menubar>
<script src="onloadoverlay.js"/>
</overlay>
我添加了菜单栏和状态栏,以确保覆盖层可以正常使用(到目前为止)。 因此,从理论上讲,以下代码应在浏览器启动时从“ onloadoverlay.js”加载,因此在加载页面时应继续加载:
onloadoverlay.js:
var myExtension = {
init: function() {
// The event can be DOMContentLoaded, pageshow, pagehide, load or unload.
if(gBrowser) gBrowser.addEventListener("DOMContentLoaded", this.onPageLoad, false);
},
onPageLoad: function(aEvent) {
var doc = aEvent.originalTarget; // doc is document that triggered the event
var win = doc.defaultView; // win is the window for the doc
// test desired conditions and do something
// if (doc.nodeName != "#document") return; // only documents
// if (win != win.top) return; //only top window.
// if (win.frameElement) return; // skip iframes/frames
alert("page is loaded \n" +doc.location.href);
}
}
window.addEventListener("load", function load(event){
window.removeEventListener("load", load, false); //remove listener, no longer needed
myExtension.init();
},false);
如果我要完全解决这个问题或缺少简单的东西,请告诉我。 到目前为止,我已经使用Google和一些扩展程序创建演练以及其他信息了。 我希望到目前为止的代码能够在页面加载时弹出一个窗口。
非常感谢您的帮助,
-Jeff
将脚本标记的src
属性更改为chrome://sample/content/onloadoverlay.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.