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.
<script
src="URI"
srcexpr="ECMAScript_Expression"
charset="encoding"
fetchhint="prefetch" | "safe"
fetchtimeout="time_interval"
maxage="integer"
maxstale="integer">
script text
</script>
|
|
Attribute |
Description |
|
src |
The URI specifying the location of the script. The URI can be one of the following formats:
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 Optional. Exactly one of src, srcexpr, expr, or an inline script must be specified. This VoiceXML 2.1 feature will be ignored if the |
|
charset |
The character encoding if an external script is used. Optional. |
|
fetchhint |
Defines when the script should be fetched. Optional.
Overrides the value of the scriptfetchhint property. |
|
fetchtimeout |
The length of time to wait for the script to be fetched before throwing an 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. |
src, srcexpr, expr, or an inline script must be specified. Otherwise, an error.badfetch event will be thrown. (However, if the restriction is violated on the initial page, the call will be rejected.)src, expr, or srcexpr will be used even if they are empty strings, and an external script fetch will be attempted (the resulting absolute URI will likely be an invalid URI and this will result in an error.badfetch event being thrown).error.semantic event when ECMAScript errors are encountered within a <script>.Block Catch Error Filled ForEach Form Help If Noinput Nomatch Vxml
#PCDATA
None
<script> cannot be used as a child of <foreach> when <foreach> is a child of <prompt> and vxmli.conformance.disallow_exec_content_within_prompts is set to true.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>
|