Friday, November 14, 2008

Include JS src file in Firefox Chrome Javascript file

To include a Javascript src file in HTML, it's very simple:
<script src="scripts/b.js" type="text/javascript"></script>
However, how to implement above logic in a Chrome js file(XUL missed including b.js).
There is a XPCOM API @mozilla.org/moz/jssubscript-loader;1
Sample:
const subScriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
 //file:/// path for XPCOM. http:// not support
subScriptLoader.loadSubScript('file:///c:/scripts/b.js', this);
In normal js file(non-chrome), it's also simple.
Sample:
document.write('<script src="scripts/b.js" type="text/javascript"></script>');
This tip is useful for Selenium-IDE enhancement.

No comments:

Post a Comment