This article is in need of a technical review.

This interface can be used from privileged JavaScript to load and run JavaScript code from the given URL at runtime.
Gecko 1.0
Inherits from: nsISupports Last changed in Gecko 8.0 (Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5)

Implemented by:;1. To get this service, use:

var mozIJSSubScriptLoader = Components.classes[";1"]
Note: See Components.utils.import for another way to import JavaScript code.

Method overview

void loadSubScript(in wstring url, in targetObj Optional, in charset Optional);



Synchronously loads and executes the script from the specified URL. As of Gecko 8.0, scripts are loaded from the startup cache where possible.

The loaded script is executed with the principal associated with the target object.

 Any variables created by the loaded script are created as properties of the targetObj target object. Additionally, properties of the targetObj target object can be referred to as variables in the loaded script.

Note: This method must only be called from JavaScript!

void loadSubScript(
  in wstring url,
  in targetObj Optional,
  in charset   Optional, 
let context = {};
                                    context, "UTF-8" /* The script's encoding */);
The URL pointing to the script to load. It must be a local chrome:, resource: or file: URL (see bug 307686 and bug 418356).

Note: In versions of Gecko prior to Gecko 1.9, you could use data: URLs as well, but this introduced security concerns, and is no longer permitted.

The object to use as the scope object for the script being executed. It defaults to the global object of the caller. Note: Undeclared variables in the loaded script will be created as global variables in the caller (ie.: in the caller's global object). This object will be searched for variables that cannot be resolved in the subscript scope.
An optional string to specify the character encoding of the file. If absent, the file is interpreted as ASCII.

See also