将 javascript 函数连接到 XUL 文件
我有一个 javascript
文件连接到我的 XUL
文件,如下所示:
<script type="application/javascript"
src="chrome://myexample/content/myexample.js"/>
XUL
文件中的覆盖层显示在 Firefox 中,但我的函数不显示工作。
例如
<statusbar id="status-bar">
<statusbarpanel id="f1"
label="f1"
onclick = "MyExample.f1()"
/>
</statusbar>
myexample.js
文件看起来像:
var MyExample = {
f1: function() {
},
f2: function() {
}
}
这是我的 chrome.manifest
:
content myexample content/
overlay chrome://browser/content/browser.xul chrome://myexample/content/myexample.xul
哪里可能有问题?
I have a javascript
file connected to my XUL
file as follows:
<script type="application/javascript"
src="chrome://myexample/content/myexample.js"/>
The overlay from the XUL
file is displayed in Firefox, but my functions aren't working.
e.g.
<statusbar id="status-bar">
<statusbarpanel id="f1"
label="f1"
onclick = "MyExample.f1()"
/>
</statusbar>
myexample.js
file looks like:
var MyExample = {
f1: function() {
},
f2: function() {
}
}
This is my chrome.manifest
:
content myexample content/
overlay chrome://browser/content/browser.xul chrome://myexample/content/myexample.xul
Where could be the fault?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了...中缺少
=
之外,您发布的代码似乎没有任何问题,不确定这是原始代码中的拼写错误还是这里的代码片段中的拼写错误。
您是否设置了 javascript.options.showInConsole 并检查错误控制台?当您打开尝试修改的窗口时是否有任何消息?
您还可能会发现 chrome 代码已被缓存。结果是您文件中的代码与 Firefox 中运行的代码不同。处理它的方法是将在同一页面上提到的disable_xul_cache首选项设置为我上面链接到的showInConsole首选项(和/或使用
-purgecaches
参数运行)。如果您有任何疑问,请对您认为已缓存的文件进行可观察的更改(即必须更改观察到的行为,例如弹出警报)。[编辑]您也可以尝试在选项卡中打开 chrome://myexample/content/myexample.js 来查看 chrome.manifest 魔法是否正常工作并且您的 URL 正确,但我想在您的情况下没问题。
There doesn't seem to be anything wrong with the code you posted, apart from the missing
=
in...not sure if that's a typo in the original code or just in the snippet here.
Did you set the javascript.options.showInConsole and check the Error Console? Are there any messages there when you open the window you try to modify?
You could also be hitting the fact that the chrome code is cached. The effect is that the code you have in your file is not the same code that's running in Firefox. The way to deal with it is to set the disable_xul_cache pref mentioned on the same page as the showInConsole pref I linked to above (and/or run with
-purgecaches
param). If you have any doubts, make an observable change (i.e. one that has to change the observed behaviour, e.g. pops an alert) to the file you think is cached.[edit] also you could try opening chrome://myexample/content/myexample.js in a tab to see if the chrome.manifest magic is working correctly and you got the URL right, but I guess in your case it's fine.
您不需要
MyExample.
部分。You dont need
MyExample.
part.