Click to enlargeWireless Markup Language<br> (WML)<a name="Top">

Scripting and Programming using WML, cHTML, and xHTML

Author: William Routt

Number of Pages: 287
Number of Illustrations: 98
Copyright: 2004


Mobile Video
Magazine
Free Subscription


Printed or Electronic Version (13.4MB) Available - Electronic Version has Color Diagrams

Wireless markup language (WML) and WMLScript are programming languages that are used to provide information services to portable wireless devices. This book explains how and why companies use WML to develop and provide information services to mobile communication devices. WML protocols and scripts are used to create web pages. more....

Sample Scripts and Diagrams

There are 98 explanatory diagrams in this book and 86 Scripting Examples

Select Command

The <select>…</select> command is used to create selection lists. Options in the list are defined with the <option>…</option> command, or the <optgroup>…</optgroup> command. Each <select> tag has one or more <option> tags, or tags within it that contain choices that the user must select from. The browser displays the text associated with each option. The multiple attribute in the <select/> command is used to specify if more than one selection is allowed. The default value is false, but if multiple is set to true, then multiple choices from the list can be made.

The name attribute of the <select/> command is required and defines the name or identifier for the variable selected in the list. The value attribute is used to specify the default selection. When the user makes a choice, the value attribute of the <option/> command becomes the value assigned to the variable. In the case when the multiple attribute is set to true, the different variable values are separated by semicolons.

The iname attribute of the <select/> command defines an alternative name for the variable that receives the number of the selection made. So, if there are three options listed, and the third option is selected, the variable name specified by iname is set to 3. The ivalue attribute is the initial value used for the variable specified in the iname attribute. If both name and iname and value and ivalue are specified, the iname and ivalue are used instead of the name and value attributes.

The title attribute of the <select> command specifies the title that appears as the title of the selection list. The tabindex attribute specifies the order of the list elements with non-negative integers. This attribute is currently not supported in some of the browsers, such as Phone.com’s browser.

Example 4.5 shows the use of the <select> command with the name, iname, value and ivalue attributes. Since ivalue takes precedence over value, the screen in Figure 4.5 shows that the initial value of the variable is set to the value specified in ivalue, not value. On the first screen, the mode is set to “car” not “plane”. The second screen shows what is seen after pressing the “Select” button. And the third screen shows the display after choosing the second choice on the list and then pushing “OK”.



WAP Push versus Pull Notifications

There are two actual methods for pushing messages down to a WAP device, push and pull. Before this chapter we have always thought of a model in which our WAP device requests a file from a server, and that server then delivers the data. This is called the pull method. The push method, on the other hand, uses the server to actually send data to the WAP device without any kind of request.

A pull notification relies on the WAP device to poll the server for new events and information. Therefore, based upon a device’s availability the message might wait at the WAP gateway until the message can be processed.

Figure 8.1 shows how push notification works with a WAP server. This example shows a WAP push proxy gateway that receives a message from a stock news information service that sends a message via the Internet when to a WAP client when a particular stock changes beyond a present limit. When the WAP push proxy gateway receives the message, it immediately alerts the WAP client of an incoming message. Because the WAP client has been setup to automatically receive these pushed messages, the WAP client acknowledges the request from the push sever and the message is delivered (pulled) from the push proxy gateway to the WAP client. This example shows that the information can be automatically displayed on the WAP client without the user having to do anything.




Table of Contents

Chapter 1 - WIRELESS SYSTEMS AND APPLICATIONS

CELLULAR AND PCS
- Wireless Data
- Paging
- Wireless Languages
- Wireless Access Protocol (WAP)
- Wireless Markup Language (WML)
- WMLScript
- XHTML Basic
SUMMARY
QUESTIONS

Chapter 2 - WIRELESS DEVICES AND OPERATING SYSTEMS

MOBILE DEVICES
- Mobile Phones
- Mobile Data Terminals
- Two-Way Pagers
MOBILE OPERATING SYSTEMS AND PLATFORMS
- BREW
- Palm OS
- EPOC
- Windows CE
- Stinger OS
MICROBROWSERS
SUMMARY
QUESTIONS

Chapter 3 - WIRELESS MARKUP LANGUAGE (WML) BASICS

BASIC STRUCTURE
INSERTING COMMENTS
VARIABLES
- Type Conversion of Variables
TEXT FORMATTING BASIC COMMANDS - Card
- Do
- Go
INPUT
- Anchor
- Table
- Prev
- Noop
SUMMARY
QUESTIONS
PROBLEMS

Chapter 4 - WML OBJECTS AND SYNTAX

TEMPLATES
IMAGES
PASSING VARIABLES
MORE COMMANDS
- Select
- Option
- Optgroup
- Refresh
- Timer
- Fieldset
- Head
- Meta
- Access
- Postfield
- Onevent
SUMMARY
QUESTIONS
PROBLEMS

Chapter 5 - WMLSCRIPT PROGRAMMING

SCRIPTING STRUCTURE
FUNCTIONS
WMLSCRIPT VARIABLES
OPERATORS
STATEMENTS AND EXPRESSIONS
CALLING WMLSCRIPT FUNCTIONS
SUMMARY
QUESTIONS
PROBLEMS


Chapter 6 - ADVANCED WML SCRIPTING

TYPE CONVERSIONS
STANDARD LIBRARIES
- String
- Lang
- Float
- URL
- WML Browser
- Dialogs
- Debug
- Console
SUMMARY
QUESTIONS
PROBLEMS

Chapter 7 - SETTING UP A WAP SERVER

NOKIA WAP SERVER
MODIFYING AN HTTP SERVER
PUBLISHING TO THE WAP SERVER
SUMMARY
QUESTIONS

Chapter 8 - CREATING PUSH AND PULL NOTIFICATIONS

WHAT ARE NOTIFICATIONS
- Alerts
- Cache Operations
- Content Messages
- Multi-part Messages
PUSH VERSUS PULL NOTIFICATIONS
SUMMARY
QUESTIONS

Chapter 9 - ADDING SECURITY TO APPLICATIONS

SECURITY BASICS - Threat Models
WAP SECURITY ARCHITECTURE
- Request Path
- WTLS and SSL
- Security Certificates
SESSION MANAGEMENT
- Client Authentication
- WML for Secure Applications
- Cleaning Up
SUMMARY
QUESTIONS

Chapter 10 - OTHER SCRIPTING LANGUAGES

XHTML
- Headers
- Linking
- Images
- Special Characters
- Tables
- Unordered Lists
- Nested and Ordered Lists
- Simple XHTML Basic Forms
- More Complex XHTML Basic Forms
CHTML
- Headers
- Linking
- Images
- Changing Text Color
- Special Characters and More Line Breaks
- Unordered Lists
- Nested and Ordered Lists
- cHTML Forms
- Summary
- Questions
- Problems
APPENDIX I
APPENDIX II
INDEX

About the Author

Mr. Routt is a communications product and technology expert and is the department head of Electronics Engineering Technology and Automation/Robotics technology at Wake Technical Community College. Mr. Routt has over 33 years of technical, research, design, development, and instruction experience. He has worked for leading companies including Bell Laboratories, DuPont, Modcomp, Siemens, Gould Computer, and several universities and colleges. Mr. Routt has been published in the Bell System Technical Journal and in the Bell Laboratories Record covering switching system technologies and telecommunications. He continually researches and develops software programs and creates courses on communications and technology automation. Mr. Routt holds many degrees and certificates including a MSEE from Carnegie Institute of Technology and a BSEE from the Pennsylvania State University.

Description

Wireless markup language (WML) and WMLScript are programming languages that are used to provide information services to portable wireless devices. This book explains how and why companies use WML to develop and provide information services to mobile communication devices. WML protocols and scripts are used to create web pages that are compatible with them.

This book describes why and how to use gateways to convert standard Internet web pages into formats that can be used by portable devices and some of the problems that this can cause. The reader will learn the structure of the WML language and how to create script files that can controls the display of information on mobile devices and the different ways that users can control content delivery of information with the limited keypads on mobile devices.

back to top WML Libraries

WMLScript is a client-side scripting language. For reference, this appendix lists all functions supported by WMLScript. Please note the following:

Like WML, WMLScript is case-sensitive.

WMLScript functions are members of function libraries, and function names are always specified as library.function (for example, String.length()).

All functions and libraries listed here are supported on all devices except where noted.

Strings may be enclosed within double quotes (as in “string”) or single quotes (as in ‘string’).

WML Library List

Lang Library

Float Library

String Library

URL Library

WML Browser Library

Dialogs Library

Debug Library

Console Library back to top

Lang Library

The lang library contains functions closely related to the WMLScript language core.

abort

Description: This function will interrupt the processing of the WMLScript and return the value of errorDescription (which must be a string) to the device.

Syntax: Lang.abort(errorDesciption)

Example: The following example interrupts WMLScript processing, and displays the error message:

// Compare passwords

if (password1!=password2) {

 // Passwords do not match

 Lang.abort(“Passwords do not match!”);

}

abs

Description: This function returns the absolute value of a specified number. If value is of type floating point, then the result is of type floating point. If value is not one of these types, then “invalid” is returned.

Syntax: Lang.abs(value)

Example: The following example returns the absolute value of the value of a specified variable:

// Get absolute value of a

var b=Lang.abs(a);

characterSet

Description: The Internet Assigned Numbers Authority (IANA) has assigned integer values for all character sets. CharacterSet returns this value.

Syntax: Lang.characterSet()

Example: The following example checks and returns the character set supported by the WMLScript interpreter:

//Check character set

function charSetTest()

 if (Lang.characterSet()==4)[

 return (“Western Europe!”);

} else {

 return (“unkown”);

}

exit

Description: This will end the rendering of the WMLScript code and present the string value. You can use this function to normally exit your WMLS code where needed.

Syntax: Lang.exit(value)

Example: The following example exits the current WMLScript and returns the specified string to the device:

// Check if okay to proceed, exit if not

if (!proceed){

 Lang.exit(“Cannot proceed as requested”);

}

float

Description: This function returns either true or false. If floating points are supported, the result is true. Otherwise, the result is false.

Syntax: Lang.float()

Example: The following example returns true if floating points are supported by the WAP browser:

// Check if floating point is supported before continuing

if (!Lang.float()){

 Lang.abort(“Cannot perform calculation”);

}

isFloat

Description: If value can be converted into a floating point, this function returns true. Otherwise, the result is false.

Syntax: Lang.isFloat(value)

Example: The following converts a floating point number to its closest integer (if it is a floating number):

// Is “a” a float?

if (Lang.isFloat(a)){

 // yes it is, convert to integer

 var b=Float.round(a);

}

isInt

Description: If value can be converted into a integer, this function returns true. Otherwise, the result is false.

Syntax: Lang.isInt(value)

Example: The following example checks to see that a specified value is an integer (and not a float); if it is not it prompts for the value again.

// Is “a” an int?

if (!Lang.isInt(a)){

 //prompt for it again

 a=Dialogs.prompt(“Please enter a valid integer value”, “”);

}

max

Description: Evaluates two values and determines which is the larger number. Whether the result is an integer or floating point is determined by the type of value1 and value2.

Syntax: Lang.max(value1,value2)

Example: The following example saves the greater of two specified values:

// Get greater value

var a = Lang.max(var1,var2);

maxInt

Description: This will return the largest supported integer value.

Syntax: Lang.maxInt()

Example: The following example initializes an integer value to the highest support value:

//Initialize to greatest possible value

var a = Lang.maxInt();

min

Description: Evaluates two values and determines which is the smaller number. Whether the result is an integer or floating point is determined by the type of value1 and value2.

Syntax: Lang.min(value1,value2)

Example: The following example saves the lesser of two specified values:

// Get lesser value

var a = Lang.min(var1,var2);

minInt

Description: This will return the smallest supported integer.

Syntax: Lang.minInt()

Example: The following example initializes an integer value to the smallest support value:

// Initialize to smallest possible value

var a = Lang.minInt();

parseFloat

 

Description: Converts a string to type floating point. Parsing ends at the first character that cannot be parsed.

 

Syntax: Lang.parseFloat()

 

Example: The following example returns 2.500000e+000:

// Prompt for temperature and parse into a float

var temp=Lang.parseFloat(Dialogs.prompt(“Temperature:”,””));

parseInt

Description: Converts a string to type integer.

Syntax: Lang.parseInt(value)

Example: The following returns the house number portion of an address:

//get house number

var house_num=Lang.parseInt(address1);

random

Description: Generates a random integer greater or equal to 0 and less than or equal to a specified value.

Syntax: Lang.random(value)

Example: The following example is a function that will return a random number between 0 and 100:

// Return a random number between 0 and 100

function GetRandom(){

 return Lang.random(100;

}

seed

Description: This initializes a random numeric sequence and also returns an empty string. If value is of type floating point, then Float.int() should be used first to convert the value to an integer.

Syntax: Lang.seed(value)

Example: The following will initialize the random numeric sequence based on the number 42:

//Initialize random sequence

Lang.seed(42);

Back to WML Library List

Float Library

The Float library contains functions used to manipulate floating point numbers.

ceil

Description: This function returns the smallest integer not less than the specified value.

Syntax: Float.ceil(value)

Example: The following example converts a floating point number to the smallest integer value not less than itself:

// Convert to integer

var b=Float.ceil(a);

floor

Description: This function returns the largest integer not greater than the specified value.

Syntax: Float.floor(value)

Example: The following example converts a floating point number to the largest integer value not greater than itself:

// Convert to integer

var b = Float.floor(a);

int

Description: Returns the integer portion of floating point value.

Syntax: Float.int(value)

Example: The following example returns the integer portion of a user-specified value:

// Extract integer portion

var b=Float.int(a);

maxFloat

Description: This will return the largest supported floating point.

Syntax: Float.maxFloat()

Example: The following example initializes a floating-point value to the highest supported value:

//Initialize to greatest possible value

var a=Float.maxFloat();

minFloat

Description: This will return the smallest supported floating point.

Syntax: Float.minFloat()

Example: The following example initializes a floating point value to the smallest supported value:

// Initialize to smallest possible value

var a = Float.minFloat();

pow

Description: Returns the value of a number raised to a specified power.

Syntax: Float.pow(value1,value2)

Example: The following example determines the cubed value of a specified number:

// Determine the cubed value of a

var b=Float.pow(a,3);

round

Description: Returns the integer that is closest to a specified value. If the two possible results are equidistant from the specified value, the result is the larger of the two.

Syntax: Float.round(value)

Example: The following example rounds a user-provided temperature to the nearest whole number:

// Round to nearest whole number

var temp2=Float.round(temp1);

sqrt

Description: Returns the square root of value.

Syntax: Float.sqrt(value)

Example: The following example determines the square root of a user-supplied number:

// Get square root

var s=Float.sqrt(a);

Back to WML Library List



String Library

The String library contains a set of string functions. In WMLScript, a string is essentially an array of characters, the first element of which is at offset 0.

charAt

Description: Returns the character at the specified position in a string.

Syntax: String.charAt(string, index)

Example: The following example returns the first letter of a user’s name:

// get initial

var initial=String.charAt(first_name,0);

compare

Description: Compares two strings. Returns 1 if first string is greater than the second string, 0 if both strings are the same, or –1 if first string is less than the first string.

Syntax: String.compare(string1,string2)

Example: The following example (part of a sorting routine) compares two strings and switches them if the first is greater than the second:

//Is a greater than b?

if (String.compare(a,b)) {

 //yes, switch a and b

 var x=a;

 a=b;

 b=x;

}

elementAt

Description: Returns the element found at a specified location within a string (using a specified delimiter).

Syntax: String.elementAt(string,index,seperator)

Example: The following example returns the first word in a sentence:

// get first word

var first_word=String.elementAt(sentence,0,” “);

elements

Description: Returns the total number of elements in a specified string.

Syntax: String.elements(string, seperator)

Example: The following example determines the number of words in a sentence:

// How many words in the sentence?

var num_words=String.elements(sentence,” “);

find

Description: Determines if a block of text is contained within a specified string. If so, the result is the index of the first character of the first occurrence of the string. If no occurrence is fouind the result is –1.

Syntax: String.find(string,substring)

Example: The following example finds the start of a page’s title text:

// Find start of page title

var a=String.find(page,”<TITLE>”);

format

Description: Converts a specified value to a string by using the given formatting provided as a format string. The format string can contain only one format specifier, which can be located anywhere inside the string. If more than one is specified, only the first one (leftmost) is used and the remaining specifiers are replaced by an empty string. The format specifier has the following form:

% [width] [.precision] type

The width argument is a non-negative decimal integer controlling the minimum number of characters printed. If the number of characters in the output value is less than the specified width, blanks are added to the left until the minimum width is reached. The width argument never causes the value to be truncated. If the number of characters in the output value is greater than the specified width, or if width is not given, all characters of the value are printed (subject to the precision argument).

The precision argument specifies a non-negative decimal integer, preceded by a period (.), which can be used to set the precision of the output value. The interpretation of this value depends on the given type:

·        d specifies the minimum number of digits to be printed. If the number of digits in the value is less than precision, the output value is padded on the left with zeros. The value is not truncated when the number of digits exceeds precision. Default precision is 1. If precision is specified as 0 and the value to be converted is 0, the result is an empty string (“”).

·        f specifies the number of digits after the decimal point. IF a decimal point appears, at least one digit appears before it. The value is rounded to the appropriate number of digits. Default precision is 6; if precision is 0 or if the period appears without a number following it, no decimal point is printed. When the number of digits after the decimal point in the value is less than the precision, letter o should be padded to fill columns. For example, the result of String.format(“%2.3f”, 1.2) will be “1.200.”

·        s specifies the maximum number of characters to be printed. By default, all characters are printed. When the width is larger than the precision, the width should be ignored.

Unlike the width argument, the precision argument can cause either truncation of the output value or rounding of a floating-point value.

The type argument is the only required format argument; it appears after any optional format fields. The type character determines whether the given value is interpreted as integer, floating-point, or sting. The supported type arguments are:

·        d Integer – the output value has the form [-]dddd, where dddd is one or more decimal digits.

·        fr Floating-point – The output value has the form [-]dddd.dddd where dddd is one or more decimal digits. The number of digits before the decimal point depends on the magnitude of the number, and the number of digits after the decimal point depends on the requested precision.

·        s String – Characters are printed up to the end of the string or until the precision value is reached.

·        % The percent character in the format string can be presented by preceding it with another percent character (%%).

Syntax: String.format(format, value)

Example: The following example formats and displays the user’s age (previously calculated):

// Display age

Dialogs.alert(String.format(“You are %d years old”, age));

insertAt

Description: Creates a string with a specified element and seperator inserted into the original string at a specified position.

Syntax: String.insertAt(string, element, index, seperator)

Example: The following example inserts an item (in variable item) at the front of a list:

// Insert new item at front of list

var list=String.insertAt(list, item,0,”,”);

isEmpty

Description: Returns a true if a string is zero-length (empty), and false if not zero-length.

Syntax: String.isEmpty(string)

Example: The following example displays an error message if a variable is not empty:

// Check e-mail address is not empty

if (String.isEmpty(email)) {

 Dialogs.alert(“E-mail address cannot be left blank!”);

}

length

Description: Returns the total number of characters in a string. The result is an integer.

Syntax: String.length(string)

Example: The following example displays an error message if a variable is not the desired length:

// Check enough digits entered

if (String.length(acn)!=12){

 Dialogs.alert(“You must enter the full 12 digit account number !”);

}

removeAt

Description: Returns a string with a specified element removed.

Syntax: String.removeAt(string, index, seperator)

Example: The following example removes the last item in a list:

// Remove last element from list

var list=String.removeAt(list, String.elements(list)-1,”,”);

replace

Description: Returns a new string where all the occurrences of a string are replaced with a new string.

Syntax: String.replace(string, oldsubstring, newsubstring)

Example: The following example replaces all occurrences of “wap” with “WAP”:

// Replace all “wap” with “WAP”

var string=String.replace(string, “wap”, “WAP”);

replaceAt

Description: Replaces a specified element in a string with a new element.

Syntax: String.replaceAt(string, element, index, seperator)

Example: The following example replaces the first item in a list with an updated value:

//Update first element

var list=String.replaceAt(list, new_value, 0,”,”);

squeeze

Description: Replaces consecutive series of white spaces in a string with one white space.

Syntax: String.squeeze(string)

Example: The following example removes any extraneous white spaces in a string:

// remove extraneous white spaces

var name=String.squeeze(name);

subString

Description: Creates a new string from a specified string, using specified start position and length.

Syntax: String.subString(string, startindex, length)

Example: The following example extracts the first sentence of a paragraph (found by looking for a period):

// Get first sentence

var sentence=String.subString(paragraph, 0, String.find(paragraph, “.”)-1);

toString

Description: Converts a value to a string.

Syntax: String.toString(value)

Example: The following example converts three parts of a phone number into strings so as to be able to concatenate them:

//Build displayable phone number

var phone=”(“+String.toString(p1)+”)”+String.tpString(p2)+”-“+String.toString(p3);

trim

Description: Removes all leading and trailing white spaces from a string.

Syntax: String.trim(string)

Example: The following example trims all leading and trailing space from an email address:

// trim address

var email=String.trim(email);

Back to WML Library List

URL Library

The URL library contains functions used in URL manipulation.

escapeString

Description: Replaces special characters contained in a string with hexadecimal equivalents.

Syntax: URL.escapeString(string)

Example: The following example escapes a URL query string:

// Escape query string

var qs=URL.escapeString(qs);

// Append to url

url=url+”?”+qs;

getBase

Description: Returns the absolute URL path of the current WMLS file.

Syntax: URL.getBase()

Example: The following example displays the URL of the script file being executed.

// Display file being executed

dialogs.alert(“Executing “+URL.getBase());

getFragment

Description: Returns the fragment (bookmark) portion of a URL.getFragment() supports both absolute and relative URLs.

Syntax: URL.getFragment(url)

Example: The following example returns a URL’s fragment:

// Get fragment

var frag=URL.getFragment(url);

getHost

Description: Returns the host name portion of a URL.getHost() supports both absolute and relative URLs.

Syntax: URL.getHost(url)

Example: The following example displays the name from which the current script being executed was retrieved:

// Display file being executed

dialogs.alert(“Executing script retrieved from “+URL.getHost(URL.getBase()));

getParameters

Description: Returns all the parameters from a URL. If URL contains no parameters, the returned string is empty.

Syntax: URL.getParameters(url)

Example: The following example extracts the query string from a specified URL:

// Get parameters

var param=URL.getParameters(url);

getPath

Description: Result is the path portion of a URL.

Syntax: URL.getPath(url)

Example: The following example extracts the path from a specified URL:

// Get path

var path=URL.getPath(url);

getPort

Description: Returns the port portion of a specified URL. If URL does not specify a port, the resule is an empty string.

Syntax: URL.getPort(url)

Example: The following example extracts the port from a URL if it exists.

// get port

var port=URL.getPort(url);

// if empty, use default of “80”

 if (port==””) {

 port =”80”;

}

getQuery

Description: Return the query string associated with URL. If URL does not contain a query string, the result is an empty string.

Syntax: URL.getQuery(url)

Example: The following example extracts the query string from a specified URL:

// get query string

var qs=URL.getQuery(url);

getReferer

Description: Returns the URL that called the current file. If there is no referrer, the result is an empty string.

Syntax: URL.getReferer()

Example: The following example goes back to the referrer:

// Go back to referrer

WMLBrowser.go(URL.getReferer());

getScheme

Description : Result is the scheme (protocol) of the current

Syntax: URL.getScheme(url)

Example: The following example extracts the scheme and saves it (assigning a default value if empty):

// get scheme

var scheme=URL.getScheme(url)

// If empty, use default of “http”

if (scheme==””) {

 scheme=”http”;

}

isValid

Description: Checks URL for the correct syntax. If URL is properly formatted, the result is true. Otherwise, the result is false.

Syntax: URL.isValid(url)

Example: The following example goes to a URL if it is valid and displays an error message if it is not:

// check if valid

if (URL.isValid(url)){

 // go to it

 WMLBrowser .go(url);

} else{

// invalid, display error message

 Dialogs.alert(url+” is not a valid URL!”)

}

loadString

Description: This function will return the content found at URL. You can only specify one content type. The content type must be text, but the subtype can be anything.

Syntax: URL.loadString(url,contenttype)

Example: The following example retrieves the content of a URL and passes it to a function for processing:

// get url and process

var content=URL.loadString(url, “text/vnd.wap.wml”);

process (content);

resolve

 

Description: Returns an absolute URL by combining a specified base URL and embedded URL. If the embedded URL is already an absolute URL, it is returned as the result of the function.

Syntax: URL.resolve(baseurl, embeddedurl)

Example: The following example resolves the root a specified URL and then goes to it:

// get host root

var resolved = URL.resolve(URL,getHost (url1), “/”)

// go for it

WMLBrowser.go(resolved);

unescapeString

Description: Converts an escaped URL string (such as any URL you might have escaped using URL.escapeString) back into the characters it represents.

Syntax: URL.unescapeString(string)

Example: The following example converts a variable to its unescaped form:

// unescape string

var unescaped=URL.unescapeString(escaped);

Back to WML Library List



WMLBrowser Library

The WMLBrowser library contains functions used to manipulate the WML browser. All these functions will return invalid if no WML browser is present or it the WMLScript interpreter is not involved by the WML browser.

getCurrentCard

Description: Result is the shortest relative URL of the current WML card.

Syntax: WMLBrowser.getCurrentCard()

Example: The following code returns the card that is currently at the top of the history stack:

// get current card

function browserCard(){

 var curCard = WMLBrowser.getCurrentCard();

}

getVar

Description: Access the value of the variable specified by name in the browser.

Syntax: WMLBrowser.getVar(name)

Example: The following code gets the value of the variable “zip” out of the WML variable stack:

// get “zip” variable

var zipvalue=WMLBrowser.getVar(“zip”);

 

go

Description: Performs the same task as the <go> element in WML. The WMLBrowser.go function is executed only after WMLS rendering is complete. You can have multiple calls to WMLBrowser.go, but each one is overriding. If the last call to this function had an empty string for the value of URL, no content would be loaded.

Syntax: WMLBrowser.go(url)

Example: The following example goes to a URL if it is valid, and displays an error message if it is not:

// check if valid

if (URL.isValid(url)){

// go to it

 WMLBrowser.go(url);

}

else {

// invalid display error message

 Dialogs.alert(url +” is not a valid URL”);

}

newContext

Description: This function operates in the same manner as the WML attribute newcontext. It erases the browser context and returns an empty string as its result.

Syntax: WMLBrowser.newContext()

Example: The following code causes the browser context to be erased:

// create new context

WMLBrowser.newContext();

prev

Description: Forces a WML <prev> task, it takes the browser back to the previous WML card. This function is executed only after all WMLS interpretation is finished.

Syntax: WMLBrowser.prev()

Example: The following code causes the browser to navigate one step backward in the history stack:

// go back one step

WMLBrowser.prev();

refresh

Description: Works the same as the WML refresh task. This function will force the browser to update its context and use the latest version of retrieved cards.

Syntax: WMLBrowser.refresh()

Example: The following code causes the current card to be refreshed:

// check if refresh needed

if (need_refresh) {

 WMLBrowser.refresh();

}

setVar

Description: The variable with the specified name is set to contain the given value in the current browser context. Variable name and its vakue must follow the syntax specified by WML.

Syntax: WMLBrowser.serVar(name, value)

Example: The following code sets the value of “done” in a variable named “status”:

// set “status”

WMLBrowser.setVar(“status”, “done”);

Back to WML Library List

Dialogs Library

The Dialogs library contains functions used to create user dialogs.

alert

Description: Allows you to send message text to the user’s device. Once the user confirms receipt of the message, an empty string is returned.

Syntax: Dialogs.alert(message)

Example: The following code expects a string input. It checks the length of the string, and if it is fewer than 8 characters, the message “Login must be longer than 8 chars” is displayed on the device screen:

// check login length

if (String.length(login) > 8 ) {

 // too short, ask again

 Dialogs.alert(“Login must be longer than 8 chars”);

}

confirm

 

Description: Allows you to send a message to the user’s device. The user is given two selection options, ok or cancel ( the text for each is specified). If the user chooses ok, the result of the function is true. Otherwise, the result is false.

Syntax: Dialogs.confirm(message, ok, cancel)

Example: The following example displays the string “Confirm your order” on the device display, and assigns a value of true to the variable named “confirm” if the user presses the accept key, and a value of false if he presses the soft1 key.

// get order confirmation

var confirm= Dialogs.confirm(“Confirm your order”, “Yes”, “No”);

prompt

Description: Allows you to send message to the user’s device prompting for input. Default input text may be provided.

Syntax: Dialogs.prompt(message, defaultinput)

Example: The following code displays the string “Enter phone number” on the device display, along with an input element that contains a default value of “650-“. When the user presses the accept key, the value is assigned to the variable named “phone”:

// get phone number

var phone = Dialogs.prompt(“Enter phone number”, “650-“);

Back to WML Library List

Debug Library

The Debug library is a Nokia-specific library containing debugging functions.

closeFile

Description: Closes an open debug file.

Syntax: Debug.closeFile()

Example: The following example opens an existing file, writes log text to it, and then closes it:

// create output file

Debug.openFile(“C:\\log\\log.txt”,”a”);

// write debug output

Debug.printLn(“Value of x is: “ + x);

// close log file

Debug.closeFile();

openFile

Description: Opens a file for reading or writing, used primarily for embedding trace information in scripts. Function supports three modes, “r” for reading, “w” for writing (overwriting existing file if present), and “a” for appending to an existing file.

Syntax: Debug.openFile(filename, mode)

Example: The following example opens an existing file, writes log text to it, and then closes it:

// create output file

Debug.openFile(“C:\\log\\log.txt”,”a”);

// write debug output

Debug.printLn(“Value of x is: “ + x);

// close log file

Debug.closeFile();

printLn

Description: Writes specified debug output to an already opened file.

Syntax: Debug.printLn(string)

Example: The following example opens an existing file, writes log ttext ot it, and then closes it:

// create output file

Debug.openFile(“C:\\log\\log.txt”,”a”);

// write debug output

Debug.printLn(“Value of x is: “ + x);

// close log file

Debug.closeFile();

Back to WML Library List

Console Library

The Console library is a Phone.com specific library containing debugging functions.

print

Description: Writes debug text to the phone information window; no new line character is inserted after the text.

Syntax: Console.print()

Example: The following example writes debug text to the phone information window:

// write debug output

Console.print(“In loop, iteration: “ + String.toString(i));

printLn

Description: Writes debug text to the phone information window and inserts a new line character after the text.

Syntax: Console.printLn()

Example: The following example writes debug text to the phone information window:

// write debug output

Console.printLn(“In loop, iteration: “ + String.toString(i));




Wireless Markup Language (WML) BK7727875$34.99

Click to enlargeeBook (pdf format)
EB7727875$29.99
Click to enlargeBook+ eBook (pdf format)
BE7727875$44.99