Specifies a block of client-side scripting logic in JavaScript.
<script
src="URI"
charset="string"
fetchhint="prefetch"|"safe"
fetchtimeout="time_interval"
maxage="time_interval"
maxstale="time_interval"
srcexpr="js_expression"
>
Script Text
</script>
Scripts do not have their own scope, but are executed in the scope of the containing element.
| Attribute | Description |
src |
|
charset |
|
fetchhint |
Specifies whether the interpreter can attempt to optimize dialog interpretation by prefetching the resource. See Prefetching Resources. Optional. |
fetchtimeout |
Specifies the interval to wait for the resource to be returned before throwing a |
maxage |
New in VoiceXML 2.0. Specifies the maximum acceptable age, in seconds, of the cached resource. See Maximum Age. Optional. |
maxstale |
New in VoiceXML 2.0. Specifies the maximum acceptable time, in seconds, during which an expired cached resource can still be used. See Maximum Stale Time. Optional. |
srcexpr |
JavaScript expression that evaluates to grammar file URI. Optional (as alternative to If you specify this attribute, the element cannot have content. |
(VoiceXML 1.0 only) The following attributes can be used in applications in which the version attribute of the <vxml> tag is set to 1.0.
| Attribute | Description |
caching |
VoiceXML 1.0 only. Specifies the caching policy for the resource being fetched. See Caching. Optional. Used in place of the VoiceXML 2.0 attributes |
|
|||
<script> <![CDATA[ function factorial(n) { return (n <= 1) ? 1 : n * factorial(n-1); } ]]> </script> |
|||
<block> <script> <!{CDATA[ function foo() { return 1; } ]]> </script> <!-- This use of foo() is legal --> Foo is <value expr="foo()"/> </block> <block> <!-- ERROR!!!! This use of foo() is illegal --> Foo is <value expr="foo()"/> </block> |
| Parents | Children |
|
| | VoiceXML 2.0 Specification: <script> |
| | JavaScript Quick Reference |
Example 1--script to get the current time:
<?xml version="1.0" ?>
<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN"
"http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
<form id="form">
<block name="time"> <!-- This block uses a java script to tell you the
time-->
<var name="hours"/>
<var name="minutes"/>
<var name="seconds"/>
<script>
var d=new Date();
hours=d.getHours();
minutes=d.getMinutes();
seconds=d.getSeconds();
</script>
<prompt>
The time is now <value expr="hours"/> hours
<value expr="minutes"/> minutes, and
<value expr="seconds"/> seconds.
</prompt>
</block>
</form>
</vxml>
Example 2 script that defines a factorial function:
<?xml version="1.0" ?>
<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN"
"http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
<property name="universals" value="help" />
<script>
<![CDATA[
function factorial(n) { return (n <= 1) ? 1 : n * factorial(n-1); }
]]>
</script>
<var name="max" expr="10"/>
<form id="form-factorial">
<field name="fact" slot="num" type="number">
<prompt>
Tell me a number and I'll tell you its factorial.
</prompt>
<catch event="help">
<prompt>
Please say a number more then zero and less than <value expr="max"/>
</prompt>
</catch>
<filled>
<if cond="fact < max">
<prompt>
<value expr="fact" /> factorial is
<value expr="factorial(fact)"/>
</prompt>
<else/>
<prompt>
Please choose a number less than <value expr="max"/>.
</prompt>
<clear namelist="fact" />
</if>
</filled>
</field>
</form>
</vxml>
| Café Home |
Developer Agreement |
Privacy Policy |
Site Map |
Terms & Conditions Part No. 520-0001-02 | © 1999-2007, BeVocal, Inc. All rights reserved | 1.877.33.VOCAL |