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:
The system does not support the WML browser.
The WMLScript 1.1 interpreter is not invoked by the WML browser.
Included in this section are the following function calls:
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.
String or invalid.
Returns invalid if there is no current card
var a = WMLBrowser.getCurrentCard();
// a = "deck#input"
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.
name = String
String or invalid.
If the syntax of the variable name is incorrect, an invalid value is returned.
var a = WMLBrowser.getVar("name");
// a = "Jon" or whatever value the variable has.
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 ("").
url = String
String or invalid
var card = "http://www.host.com/loc/app.dck#start";
WMLBrowser.go(card);
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.
String or invalid
WMLBrowser.newContext();
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 ("").
String or invalid
WMLBrowser.prev();
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.
String or invalid.
Returns invalid if there is no current card
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();
}
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.
name = String
value = String
Boolean or invalid.
If the syntax of the variable name or its value is incorrect, an invalid value is returned.
var a = WMLBrowser.setVar("name", "Mary"); // a = true