<script>

Description

Includes a block of client-side ECMAScript.  If a <script> occurs as a child of <vxml>, it is evaluated just after the document is loaded, in document order.  If a <script> occurs as a child of a <form>, it is evaluated in document order each time execution moves into the <form> element.  If a <script> occurs in executable content, it is evaluated as it is encountered.  Each <script> element is executed in the scope of its containing element; i.e., it does not have its own scope.  Variables defined in <script> are equivalent to variables defined using <var> within the same scope.

 

See the ECMAScript reference for details on both standard and VoiceGenie-defined features.

Syntax

<script
    src="URI"
    srcexpr="ECMAScript_Expression"
    charset="encoding"
    fetchhint="prefetch" | "safe"
    fetchtimeout="time_interval"
    maxage="integer"
    maxstale="integer">
  script text
</script>

Attributes

Attribute

Description

src

The URI specifying the location of the script.  The URI can be one of the following formats:

  • External script file: URL of the script file
  • Local scripts: builtin:[path/]filename
    (a script named /usr/local/phoneweb/script/[path/]filename or C:\VoiceGenie\mp\script\[path\]filename must exist on the VoiceGenie platform)

Optional.  Exactly one of src, srcexpr, expr, or an inline script must be specified.

srcexpr

An ECMAScript expression evaluating to the URI of the script file, as documented under src, above.

Optional.  Exactly one of src, srcexpr, expr, or an inline script must be specified.

This VoiceXML 2.1 feature will be ignored if the <vxml> version attribute is set to a value lower than 2.1 (i.e. 2.0 or 1.0).

charset

The character encoding if an external script is used.  Optional.

fetchhint

Defines when the script should be fetched. Optional.

  • prefetch - script may be downloaded when the page is loaded
  • safe - only load the script when needed

Overrides the value of the scriptfetchhint property.

fetchtimeout

The length of time to wait for the script to be fetched before throwing an error.badfetch event. Optional.

Overrides the value of the fetchtimeout property.

maxage

Indicates that this document is willing to use a cached copy of the script only while the age of the cached copy is less than or equal to the number of seconds specified by this attribute.  Optional.

Overrides the value of the scriptmaxage property.

maxstale

Indicates that this document is willing to use a cached copy of the script that has exceeded its expiration time by as much as the number of seconds specified by this attribute.  Optional.

Overrides the value of the scriptmaxstale property.

Attribute Notes

Parents

Block Catch Error Filled ForEach Form Help If Noinput Nomatch Vxml

Children

#PCDATA

VoiceGenie Extensions

None

Limitations/Restrictions

Example

It is wise to put CDATA escapes around your scripts so you don't have to escape XML reserved characters (eg. <, >, &, etc).

<?xml version="1.0"?>
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
  <form>
    <script>
      <![CDATA[
        var n = 5;
        function square(factor) {
          return factor*factor;
        }
      ]]>
    </script>
    <block>
      <value expr="n"/> squared is <value expr="square(n)"/>.
    </block>
  </form>
</vxml>