Chapter 15. Scripting ELinks with ECMAScript
Prev |  | Next

## Chapter 15. Scripting ELinks with ECMAScript

As a user of ELinks, you can control its behaviour by writing scripts in ECMAScript. Unlike scripts in SCRIPT elements of HTML, these user scripts run with all the permissions of your user account, the same as with Lua. The object model is very different too.

Support for ECMAScript user scripts was first added in ELinks 0.11.0. The `configure` script enables it by default if the required SpiderMonkey library has been installed, but you can disable it with `configure --disable-sm-scripting` or by editing features.conf.

### Warning

ECMAScript scripting is still a bit experimental: there seem to be ways to crash ELinks with it, and the object model may change. However, if you don't have a `hooks.js` file, there is not much risk in enabling the feature at compile time.

When ELinks starts up, it evaluates the ECMAScript file `hooks.js` in your ELinks configuration directory (thus normally `~/.elinks/hooks.js` on Unix-like systems), or if the file does not exist there, then in the system-wide ELinks configuration directory (the location depends on how ELinks was built, but `/etc/elinks/hooks.js` is typical).

In the ELinks source tree, the `contrib/smjs` directory contains some examples about scripting ELinks with ECMAScript. Please see the `README` file in that directory for details.

## Global Object

The global object provided to ECMAScript user scripts contains the standard ECMAScript classes, as well as the following:

### Global Object Methods

do_file(path)

  Load and evaluate the file with the given path (string). For example:

      do_file("/home/me/.elinks/hooks.js");

  will reload your hooks file.

  Compatibility: ELinks 0.11.0

### Global Object Properties

elinks (elinks)

  A reference to the ELinks object.

  Compatibility: ELinks 0.11.0

Prev |  | Next
Example recipes | Home | ELinks Object