Script execution (Definition)

The process of running script.

Scripts are executed in several different ways according to the context and environment in which they are run.

Script code enclosed inside <SCRIPT> tags in a web page is executed as the page is rendered or when the browser generates events. Some of the code (the global code) is executed as the page is loaded. Code contained in functions is called as it is needed, however it's probably a good idea not to call function code that is defined in <SCRIPT> tags within the <BODY> from global code that is in the <HEAD> of a web page. Some implementations may not mind but others may fail.

Some web browsers will allow you to access objects within the document while it is being built, others will only allow access to objects once the closing </BODY> tag has been processed. This suggests that there is some fixing up of the internal object referencing structures that is required before the DOM tree can be traversed. An example of this is the way that MSIE handles <DIV> and <OBJECT> tags. You may not reference an <OBJECT> tag from a script until the body.onLoad event. You can sometimes access <DIV> blocks after they have been created but before the </BODY> has been reached. This behaviour may be version-specific and also OS-specific and it may be that Macintosh and Windows versions of a browser behave differently. In the case of MSIE and Netscape Navigator, the rendering engines of both were rewritten at versions 5 and 6 respectively, and therefore many previous problems will be gone, only to be replaced by many new ones.

Scripts may be activated by a CGI interface when they are used in the middle-ware part of a server-side solution. These implementations will generally lack any kind of document model but instead will have a file system model and possible a means of reaching a database.

Scripts in embedded implementations may be triggered by a variety of situations. TV set-top boxes may trigger a JavaScript in receipt of a URL encoded into the vertical interval of the TV signal. This is a way of hiding URL data in the same way as closed caption and teletext information. Analogue TV is being phased out over the next few years but similar mechanisms will be provided with the new digital TV platforms.

Scripts used in WAP phones provided a card and stack metaphor very like HyperCard. This is embodied in WML and WScript. The scripts are the mechanism by which the pages are presented to the user. They are transmitted in a compact byte-code form, which needs to be compiled before delivery.


See also:<SCRIPT EVENT="...">, Event, Event handler in <SCRIPT>, Host environment, iCab, Internet Explorer, Netscape Navigator, OpenTV, Opera, PDF, Platform, Script, Script termination, Side effect, Storage duration, WebTV, WScript


O'Reilly JavaScript Definitive Guide - page - 221-5

Wrox Instant JavaScript - page - 5