<script>

Contains ECMAScript code for executing on the client side. The <script> element allows you to include scripting language code in your application. The <script> element can contain any ECMAScript code. Code contained in the <script> element is executed on the client side by the Nuance VoiceXML interpreter.

Attributes

This section describes the attributes you can set for this element.

Name

Data type

Default

charset

CDATA

optional

fetchhint

(prefetch | safe)

optional

fetchtimeout

CDATA

optional

maxage

CDATA

optional

maxstale

CDATA

optional

src

CDATA

optional

srcexpr

CDATA

optional

charset

The charset attribute specifies the character encoding of the remote script. For example:

<script src="remote_script.js" charset="ISO8859_1"/>

For a complete listing of all encoding types, click here.

Note: Voice Platform supports all encoding types supported by Java2.

fetchhint

The fetchhint attribute determines when content is retrieved from the server. The settings for the fetchhint attribute are prefetch and safe. The prefetch setting indicates that files or dialogs are downloaded when a page is loaded. The safe setting indicates that files or dialogs are downloaded only when they are actually needed.

If you do not specify a setting for the fetchhint attribute, the <property> element determines the setting by defining a value for the appropriate *fetchhint property, for example:

<property name="documentfetchhint" value="safe"/>

fetchtimeout

The fetchtimeout attribute specifies the amount of time to wait for the content to be fetched before throwing an error.badfetch event.

The value may be specified in seconds (s) or milliseconds (ms). If no unit is specified, the value is interpreted as milliseconds by default. If no value is specified, the fetchtimeout defaults to the value set an applicable <property> element, or to the value set for the browser.loading.fetchtimeout property in Management Station if no <property> applies. If no other default applies, the platform default of 10000 milliseconds is used.

maxage

The maxage attribute specifies the maximum amount of time a fetched resource may remain in the locale cache without requiring a server revalidation. If a value for the maxage attribute is not specified, revalidation will occur after the expiration of the freshness lifetime (as defined in RFC 2616).

maxstale

The maxstale attribute specifies the maximum amount of time a stale file remains valid before a refetch is required. If a value for the maxstale attribute is not specified, the stale document is refetched.

src

The src attribute specifies the URI location of the script file. Note that only one src attribute or PCDATA inline content may be specified.

srcexpr

Implemented in VoiceXML 2.1.

The srcexpr attribute is equivalent to src except that here, the URI is dynamically determined by evaluating the given ECMAScript expression. The expression must be evaluated each time the script needs to be executed, otherwise an error.semantic event is thrown.

Exactly one of src, srcexpr, or an inline script must be specified, otherwise an error.badfetch event is thrown.

This example retrieves a script from a URI that is composed at runtime using the variable scripts_baseuri:

<var name="scripts_baseuri" expr="'http://www.example.org/'"/>
<form>
  <script srcexpr="scripts_baseuri + 'lib/util.js'"/>
</form>

Children

Parsed character data

Parents

Sample code

<vxml>
    <script>
        var d = new Date();
        hours = d.getHours();
        minutes = d.getMinutes();
        seconds = d.getSeconds();
    </script>
    <form>
        <block>
            The time is <value expr="hours"/> hours,
            <value expr="minutes"/> minutes, and
            <value expr="seconds"/> seconds.
        </block>
    </form>
</vxml>

For a VoiceXML sample demonstrating the use of the <script> element, see Blackjack.vxml located in $NVP_HOME/appservice/applications/webapps/BlackJack . For information about samples, see Sample applications.