1

I've read around and found techniques to add js file inside XBL, but the techniques don't work. I tried to declare the tag: <'script src='test.js''> and <'script src='chrome://content/test.js '>, but none worked.

The method inside the test class is simply function caller() { alert("call succeeded"); }.

Is there a correct and simple way to include js file inside XBL, so calling functions from the file works as if the function were written inside the XBL.

The Student
  • 27,520
  • 68
  • 161
  • 264
user375065
  • 57
  • 5

2 Answers2

2

Here's some more details: http://www.w3.org/TR/xbl-primer/#scripts What you're doing seems to be fine, here's the example they're giving:

<xbl xmlns="http://www.w3.org/ns/xbl">
  <script src="example.js"/>

Note xmlns there, that's default namespace. If you have it defined as: xmlns:xbl="http://www.w3.org/ns/xbl" then you have to use

<xbl:script src="example.js" />

Try that, I never tried it personally myself but this namespace thing is common pitfall.

EDIT: I'm afraid that this might not be possible. This is from XBL 2.0 spec, and Gecko doesn't seem to be supporting it yet, and in XBL 1.0 script tag does not exist:

http://groups.google.com/group/mozilla.dev.tech.xbl/msg/d7d4f279ebdad65f?pli=1 They are mentioning here that development should get into full swing.

Here's the link to which they are pointing to: https://wiki.mozilla.org/XBL2 but it seems that it hasn't been updated since 2009, it's hard to tell if this is even going to be implemented.

And here's XBL 1.0 reference where you can see that script tag does not exist: https://developer.mozilla.org/en/XBL/XBL_1.0_Reference

But to offer a possible alternative - you could use modules, and in constructor do something like this:

<constructor>
    Components.utils.import("resource://yourextension/config.js");

For more on modules: https://developer.mozilla.org/en/JavaScript_code_modules and example: https://developer.mozilla.org/en/JavaScript_code_modules/Using Basically you'd need to register your modules folder put your test.js in it, follow the instructions how to "export" functions/variables from it. You can then import it to any JavaScript, XUL or XBL file.

Mihailo
  • 754
  • 3
  • 6
  • This is the original namespace xmlns="http://www.mozilla.org/xbl" xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:xbl="http://www.mozilla.org/xbl" > – user375065 Feb 18 '11 at 15:55
  • try <script src='chrome://content/test.js' > but remove xmlns:xbl, you already have xmlns – Mihailo Feb 18 '11 at 16:01
  • Its strange I need both for the binding to work. I tried it with complete source it still doesn't work. I am beginning to hate xbl – user375065 Feb 18 '11 at 16:08
  • actually I have them both in (doh!) Can you post the whole file? – Mihailo Feb 18 '11 at 16:16
  • can you send your email me ur email address my email address is r.m11288@googlemail.com – user375065 Feb 18 '11 at 16:33
  • thank you very much for your help. I wan so close to bashing the screen off my laptop :) – user375065 Feb 19 '11 at 17:13
1

XBL1 doesn't support script tags. The best you can do is to import functions from a module when you need them.

Neil
  • 54,642
  • 8
  • 60
  • 72