页面加载后从 XUL 调用 Init(Firefox 附加组件)
我一直在 js/html 中编写一些代码,效果很好。我现在正尝试将其打包到 Firefox 的附加组件中,但在正确获取 XUL 文档时遇到了一些问题。
PLAIN OLD HTML/JS
在 之间的 html 测试文件中,我有:
<script type="text/javascript" src="js/MyCode.js"></script>
在 之前的测试文件末尾
我有:
<script type="text/javascript">MyCode.Static.Init();</script>
FIREFOX ADD-ON: OVERLAY.XUL
在扩展包的一个overlay.xul文件中我有:
<?xml version="1.0"?>
<overlay id="mycode"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://mycode/content/MyCode.js"></script>
<script>
window.addEventListener("load", function () { gBrowser.addEventListener("load",MyCode.Static.Init,true); }, false);
</script>
</overlay>
这似乎没有进入方法,但是话又说回来,我什至不确定我是否让听众正常射击。这是复制我在普通旧 html/js 中所做的事情的正确方法吗?
I've been working on some code in js/html and it works great. I'm now trying to package it into an add-on for Firefox, and having some issues getting the XUL document correct.
PLAIN OLD HTML/JS
In my html test file between the <head></head>
I have:
<script type="text/javascript" src="js/MyCode.js"></script>
At the end of the test file before the </body>
I have:
<script type="text/javascript">MyCode.Static.Init();</script>
FIREFOX ADD-ON: OVERLAY.XUL
In an overlay.xul file in the extension package I have :
<?xml version="1.0"?>
<overlay id="mycode"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://mycode/content/MyCode.js"></script>
<script>
window.addEventListener("load", function () { gBrowser.addEventListener("load",MyCode.Static.Init,true); }, false);
</script>
</overlay>
This does not seem to enter the method, but then again I'm not even sure if I've got the listeners firing properly. Would this be the correct way to duplicate what I was doing in plain old html/js ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请参阅:https://developer.mozilla.org/en/Code_snippets/Progress_Listeners如何捕获所有页面更改/加载/重新加载
See: https://developer.mozilla.org/en/Code_snippets/Progress_Listeners for how to catch all page changes/loads/reloads
您确定 gBrowser 已准备好吗?
作为健全性检查,将脚本标记更改为 以
确保 gBrowser 已准备就绪。
Are you sure that gBrowser is ready?
Just as a sanity check, change the script tag to
to make sure that gBrowser is ready.
这是正确的:
gBrowser.addEventListener("load",function () { MyCode.Static.Init(); }, false);
This is correct:
gBrowser.addEventListener("load",function () { MyCode.Static.Init(); }, false);
怎么样:
?
How about:
?