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.
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:
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
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:
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.