Appendix A. Configuration Script Syntax

Table of Contents
Scripting Guide
API Reference

Scripting Guide

Important: This section does not describe how to program JavaScript or give detailed descriptions of it's syntax. You may be able to get by extending the simple examples with no knowledge of JavaScript, but you would do well to get yourself a book and learn to write more advanced scripts.

The scripts used by Flight Simulator are written in JavaScript. The environment these scripts run in differs from the environment available to scripts running on web pages, though the core set of JavaScript objects are be available (e.g. Math, Boolean).

In addition, FlightSimulator provides JavaScript objects which allow you to easily make requests to the webserver.

Example A-1. A simple script

// A simple example
agent.setHost("www.goodtechnology.com");
agent.get("/");

This script, when run, will request the GoodTech homepage. The first line starting with // is a comment. All text on a line after this symbol will be ignored. The second line instructs Flight Simulator that subsequent requests should be made to the server www.goodtechnology.com. The third line actualy tells Flight Simulator to request GoodTech's homepage.

Example A-2. Setting the referring page

// Referrer example
agent.setHost('www.goodtechnology.com');
agent.get('/');
agent.setHeader('Referer', 'http://www.goodtechnology.com/');
agent.get('/page2.jsp');

This example extends the first by requesting a second page and telling Flight Simulator to inform the server of the referring page. This information is sent by a web browser to tell the server what page is being linked from. Most of the time you won't need to bother with the referrer; only occasionaly do server-side components examine it.

The agent.setHeader() function allows you to send an arbitrary HTTP header with the next request. If you wanted to specify a header to be sent with every subsequent request, you can use the agent.setPersistantHeader() function.

Example A-3. Setting a persistant header

// Set the user-agent
agent.setPersistentHeader('User-Agent', 'Mozilla/4.0');
agent.setHost('www.goodtechnology.com');
agent.get('/');
agent.get('/anotherpage.jsp');

Here, we will send the User-Agent header with both requests to the server. This would be useful for testing systems that recognise the browser making a request and modify their content to suit.

Example A-4. Posting a form

// Set the user-agent
agent.setHost('www.goodtechnology.com');

var myForm = new Form();
myForm['firstname'] = 'David';
myForm['secondname'] = 'Holroyd';

agent.post('/register.jsp', myForm);

The form object is created and two form fields are defined. [ ... ]