简体   繁体   English

将javascript函数连接到XUL文件

[英]Connecting javascript functions to XUL file

I have a javascript file connected to my XUL file as follows: 我有一个连接到我的XUL文件的javascript文件,如下所示:

<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. XUL文件的叠加层显示在Firefox中,但是我的功能无法正常工作。

eg 例如

<statusbar id="status-bar"> 
<statusbarpanel id="f1"  
    label="f1"
    onclick = "MyExample.f1()"
  />
</statusbar>

myexample.js file looks like: myexample.js文件如下所示:

var MyExample = {
  f1: function() {
  },
  f2: function() {
  }
}

This is my chrome.manifest : 这是我的chrome.manifest

content   myexample  content/
overlay chrome://browser/content/browser.xul  chrome://myexample/content/myexample.xul

Where could be the fault? 哪里可能出问题了?

There doesn't seem to be anything wrong with the code you posted, apart from the missing = in 您发布的代码似乎没有任何问题,除了缺少= in

var MyExample = {

...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? 您是否设置了javascript.options.showInConsole并检查了错误控制台? 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. 您也可能会碰到Chrome代码被缓存的事实。 The effect is that the code you have in your file is not the same code that's running in Firefox. 结果是文件中的代码与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). 处理它的方法是设置与我上面链接到的showInConsole首选项相同的页面上提到的disable_xul_cache首选项(和/或使用-purgecaches参数运行)。 If you have any doubts, make an observable change (ie one that has to change the observed behaviour, eg 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. [edit]另外,您也可以尝试在标签中打开chrome://myexample/content/myexample.js,以查看chrome.manifest魔术是否正常运行,并且您输入的网址正确无误,但我想您的情况还可以。

You dont need MyExample. 您不需要MyExample. part. 部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM