WMLScript Reference

[Cover] [Previous Section] [Next Section] [Index]

Current chapter: Chapter 8 - Libraries
Section 29 out of 34 total sections , Section 7 out of 9 sections in this chapter


WMLBrowser Library

The WMLBrowser library contains functions by which WMLScript 1.1 can access the associated WML context. These functions must not have any side effects, and they must return invalid in the following cases:

Included in this section are the following function calls:

Function call 

getCurrentCard 

getVar 

go 

newContext 

prev 

refresh 

setVar 



getCurrentCard

WMLBrowser.getCurrentCard()  

Returns the smallest relative URL (relative to the base of the current file) specifying the card (if any) currently being processed by the WML browser. For more information, visit:

http://www.wapforum.org  

The function returns an absolute URL if the WML deck containing the current card does not have the same base as the current file.


Return Value

String or invalid.


Exceptions

Returns invalid if there is no current card


Examples

var a = WMLBrowser.getCurrentCard();  
    // a = "deck#input"  


getVar

WMLBrowser.getVar(name)  

Returns the value of the variable with the given name in the current browser context. Returns an empty string ("") if the given variable does not exist.

Variable name must follow the syntax specified by WML.


Parameters

name = String


Return Value

String or invalid.


Exceptions

If the syntax of the variable name is incorrect, an invalid value is returned.


Examples

var a = WMLBrowser.getVar("name");  
    // a = "Jon" or whatever value the variable has.  


go

WMLBrowser.go(url)  

Specifies the content denoted by the given url to be loaded. This function has the same semantics as the GO task in WML. The content is loaded only after the WML browser receives control from the WMLScript 1.1 interpreter after the WMLScript 1.1 invocation is finished. No content is loaded if the given url is an empty string ("").

go() and prev() library functions override each other. Both of these library functions can be called multiple times before returning control to the WML browser. However, only the settings of the last call stay in effect. In particular, if the last call to go() or prev() set the URL to an empty string (""), all requests are effectively cancelled.

This function returns an empty string ("").


Parameters

url = String


Return Value

String or invalid


Examples

var card = "http://www.host.com/loc/app.dck#start";  
WMLBrowser.go(card);  


newContext

WMLBrowser.newContext()  

Clears the current WML browser context and returns an empty string (""). This function has the same semantics as the NEWCONTEXT attribute in WML.


Return Value

String or invalid


Examples

WMLBrowser.newContext();  


prev

WMLBrowser.prev()  

Signals the WML browser to go back to the previous WML card. This function has the same semantics as the PREV task in WML. The previous card is loaded only after the WML browser receives control from the WMLScript 1.1 interpreter after the WMLScript 1.1 invocation is finished.

prev() and go() library functions override each other. Both of these library functions can be called multiple times before returning the control back to the WML browser. However, only the settings of the last call stay in effect. In particular, if the last call to go() or prev() set the URL to an empty string (""), all requests are effectively cancelled.

This function returns an empty string ("").


Return Value

String or invalid


Examples

WMLBrowser.prev();  


refresh

WMLBrowser.refresh()  

Forces the WML browser to update its context and returns an empty string. This function has the same semantics as the REFRESH task in WML. For more information, visit:

http://www.wapforum.org  

The function returns an absolute URL if the WML deck containing the current card does not have the same base as the current file.


Return Value

String or invalid.


Exceptions

Returns invalid if there is no current card


Examples

Following is sample code that uses the WMLBrowser.refresh function call.

function convert2Peso(){  
    var dollars = WMLBrowser.getVar("amount");
    var dol2peso = 10.2;
    var newAmt = dollars*dol2peso;
 

    WMLBrowser.setVar("amount", newAmt);
    WMLBrowser.refresh();
 

}  


setVar

WMLBrowser.setVar(name, value)  

Returns true if the variable with the given name is successfully set to contain the given value in the current browser context; false otherwise.

Variable name and its value must follow the syntax specified by WML. Variable value must be legal XML CDATA.


Parameters

name = String

value = String


Return Value

Boolean or invalid.


Exceptions

If the syntax of the variable name or its value is incorrect, an invalid value is returned.


Examples

var a = WMLBrowser.setVar("name", "Mary");    // a = true  

[Cover] [Previous Section] [Next Section] [Index]


Part Number DKWS-41-002, UP.SDK Release 4.1, December 2000

Copyright © 1994-2000 Openwave Systems Inc. All rights reserved.
Please send comments and questions to sdk-doc-comments@openwave.com.