Using the browser object
Use the Voice Platform implementation of the ECMAScript browser object to collect information about executing VoiceXML documents or to debug ECMAScript code. This section describes the properties and methods that are supported by the browser object.
Also see, Removing cookies from the cache.
The location property returns the URL of the executing VoiceXML document, for example:
<vxml version="2.0">
<script>
/*This example assumes the name of the executing document is foo.vxml. As a result, the value returned by location property will be <http://company.com/foo.vxml>*/
var loc = browser.document.location
</script>
</vxml>
The applicationName property returns the URL of the VoiceXML application’s root document, for example:
<vxml version="2.0" application="bar.vxml">
<script>
/*Since the root document in this example is bar.vxml,
this means applicationName property will return <http://company.com/bar.vxml>*/
var root = browser.document.applicationName
</script>
</vxml>
The cookie property adds cookies to the current document’s existing list of cookies, for example:
<script>
/*Setting cookies "jsone" and "jstwo" with appropriate
values and expiration times*/
browser.document.cookie = "jsone=1;Max-Age=3600, jstwo=2;Max-age=10";
</script>
The next snippet shows you how to access the cookie property. When accessing this property, the current document’s list of cookies is returned.
<script>
var cookies = browser.document.cookie;
</script>
Given the first example, this means the value of the cookies variable is "jsone=1;jstwo=2".
The browser.document.findcookie method searches through the current document’s existing list of cookies and returns the value of a given cookie, for example:
<script>
var one = browser.document.findCookie("jsone");</script>
If you refer to the first example in section browser.document.cookie, this means the value of variable one is 1.
The browser.log method allows you to debug your ECMAScript code. This method takes two arguments and returns no values.
The syntax for this method is:
<script>
browser.log(destinationURI, messageText)
</script>
Where:
- destinationURI specifies where to route the debugging information. Voice Platform supports three destination types: trace messages, call log events, and
catalogued messages. - Trace messages are sent to Voice Browser service diagnostic log files for browser logging. The destinationURI for trace messages is specified as follows:
browser.log('trace:?level=WARN', 'The value of x is ' + x);
See the label attribute for the complete list of supported debug levels.
- Call log events are sent to Voice Platform call log files. The destinationURI for call log events is specified as follows:
browser.log('callog:?key=My_X_VAR', 'value of the key');
- Catalogued messages are sent to diagnostic log files using the Voice Platform message catalog URL. This message catalog URL is specified as follows:
browser.log("message:?subsystem_name=com.nuance.DIALER &subsystem_id=32768&level=MINOR_ALARM
&offset=1&version=1.0", "Too many no-speech-timeouts");
- messageText specifies the string message to log, for example:
browser.log('trace:?level=WARN', 'The value of x is ' + x);