Script

From Frontal Wiki

Jump to: navigation, search

Introduction to the script tag

The "script" tag is used to add Frontal scripting to a document definition. It's basic form is like so:

<script><![CDATA[
    // The script goes here.
    //
]]></script>

For information about Frontal scripting, see the section Frontal Scripting.

Implementation

The script tag is implemented with the DocElemScript class which extends DocumentElement. As such, the script tag is a normal document element and may have styles and attributes applied to it if that is desired. It processes its own content though and so cannot contain other elements.

As its own DocumentElement, any code inside the script tag runs in the context of the script tag. That is, for example, this will display the XML of the script tag itself:

<script><![CDATA[
    com.frontalcode.Debugger.msg ( com.frontalcode.Util.htmlEscape ( node.toXMLString ( ) ) );
]]></script>

This fact can make it convenient to use script to manipulate a nearby tag. For example, here we use a script tag to change the style of its parent div.

<div>
    <script><![CDATA[
        parent.sS ( "width", "100%" );
        parent.sS ( "height", "100%" );
        parent.sS ( "background-color", "orange" );
    ]]></script>
</div>

Note though that the script in a script tag is only run once and at the time the Frontal definition is parsed. (See the advanced topic on How Frontal is Parsed and Rendered.) This means that the other elements have likely not been rendered yet and so properties like movie, image and video are not yet populated. To write scripts that manipulate those display objects, then use interactions. See Adding Interactions.

Personal tools
Get Adobe Flash player