简体   繁体   English

在xbl / xul文件中加载javascript模块的正确方法是什么?

[英]what is the right way of loading javascript module in the xbl/ xul file?

I am developing an extension in Firefox. 我正在开发Firefox中的扩展程序。 I want to load a simple javascript module to my xbl file. 我想将一个简单的javascript模块加载到我的xbl文件中。 I have followed the instructions in here but I don't get any results. 我已按照此处的说明进行操作,但未得到任何结果。 In fact when I call the method inside the handler it doesn't execute. 实际上,当我在处理程序内部调用该方法时,它不会执行。

This is my file structure for extensions 这是我的扩展文件结构

-Magic/chrome/urltooltip/content/(browse.xbl, options.xul, browser.css) -Magic / chrome / urltooltip / content /(browse.xbl,options.xul,browser.css)

-Magic/modules/(test.js) -魔术/模块/(test.js)

I have registered resource in chrome manifest: resource app chrome://modules/test.js or resource gre chrome://modules/test.js it doesn't work. 我已经在chrome清单中注册了资源:资源应用chrome://modules/test.js或资源gre chrome://modules/test.js,它不起作用。

in the xbl file I imported the file like this: 在xbl文件中,我像这样导入文件:

Components.utils.import(resource://app|gre/modules/test.js) Components.utils.import(资源:// app | gre / modules / test.js)

I don't know what else to do. 我不知道该怎么办

Use something like this: 使用这样的东西:

<?xml version="1.0"?>

<window xmlns:html="http://www.w3.org/1999/xhtml"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script src="foo.js"></script>

  <script>
    <[CDATA[
      function bar() {}
    ]]>
  </script>

  <caption label="Hello World"/>

</window>  

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

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