WML Script

WML Script

R4R provide basic WMLScript Tutorials concept with WMLScript Examples .Through R4R you can develop WMLScript programming concept. R4R provide WMLScript Interview Questions with answers.R4R provide WMLScript Languages study materials in easy way.

Introduction of WMLScript

The WMLScript language is part of the industry-wide standard for wireless applications called Wireless Application Protocol (WAP) .WMLScript (Wireless Markup Language Script) is the client-side scripting language of WML (Wireless Markup Language). WMLScript is work with WML pages. And WML pages can displayed on WAP browser. Using WMLScript we can validate user input, generate dialog boxes, view error messages, access facilities of the user agent etc.

A scripting language is similar to a programming language, but it is light weight. With WMLScript , the wireless device can do some of the processing and computation. This reduces the number of requests and responses to/from the server. In the old days, fewer round-trips can improve the performance of your WAP site significantly since data transmission over wireless networks is slow.

Today, the performance gained may not be so significant any more as data transmission speed has improved a lot. However, you may still find WMLScript useful since putting some operations at the client-side can reduce the load of your servers.

WMLScript is based on ECMAScript (European Computer Manufacturers Association Script), which is JavaScript's standardized version. So, the syntax of WMLScript is very similar to JavaScript. (In case you do not know, JavaScript is a scripting language commonly used on the web.) If you have some programming experience with JavaScript, you should be able to learn WMLScript quickly.

Diffrence between Javascript and WMLScript

A most important difference between JavaScript and WMLScript is that JavaScript code can be embedded in the HTML markup, whereas WMLScript code is always placed in a file separated from the WML markup. URLs are used to refer to the actual WMLScript code in the WML document.

Some Other Diffrence
Feature WMLScript JavaScript
Semicolons Mandatory Optional
Supports HTML CommentsNo Yes
Non-escape characters preceded by a backslashNo Yes
Names may include $ charactersNo Yes
Supports global variablesYes Yes
typeof returnsan integer a string
Supports arraysNo Yes
Supports objectsNo Yes


WML Scripts Standard Libraries

WMLScript has a core group of six standard libraries. Each of the various libraries contains from three to seventeen functions that perform useful tasks related in concept to the library name.

The six standard libraries are
  1. Lang Library
  2. Float Library
  3. String Library
  4. URL Library
  5. WMLBrowser Library
  6. Dialogs Library
  • Lang- The Lang library provides functions related to the WMLScript language core. Example Function: abs(),abort(), characterSet(),float(), isFloat(), isInt(), max(), isMax(), min(), minInt(), maxInt(), parseFloat(), parseInt(), random(), seed()
  • Float-The Float library contains functions that help us perform floating-point arithmetic operations. Example Function: sqrt(), round(), pow(), ceil(), floor(), int(), maxFloat(), minFloat()
  • String-The String library provides a number of functions that help us manipulate strings. Example Function: length(), charAt(), find(), replace(), trim(), compare(), format(), isEmpty(), squeeze(), toString(), elementAt(), elements(), insertAt(), removeAt(), replaceAt()
  • URL- The URL library contains functions that help us manipulate URLs. Example Function: getPath(), getReferer(), getHost(), getBase(), escapeString(), isValid(), loadString(), resolve(), unescapeString(), getFragment()
  • WMLBrowser- The WMLBrowser library provides a group of functions to control the WML browser or to get information from it. Example Function: go(), prev(), next(), getCurrentCard(), refresh(), getVar(), setVar()
  • Dialogs- The Dialogs library Contains the user interface functions. Example Function: prompt(), confirm(), alert()
  • Advantage of WMLScript
    1. To check the legitimacy of user input
    2. To expand the functions of the user's browser, for example, allows programmers to develop mobile phone calls, send text messages, store phone numbers, phone book or SIM card management, etc.
    3. To generate the client confirmed that prompts a warning message or dialog box operation, and quickly displayed in the browser.
    4. Change the user's browser, the browser client to the software and the expansion and configuration parameters.
    Working Of WMLScript with Example

    WMLScript functions or statements are not defined inside a WML page. Instead, all WMLScript language or statements are stored in another file with file extension .wmls (Wireless Markup Language Script).When your WML page calls a WMLScript function, you call the reference of the function by URL. When a function of WMLScript is called, the script is compiled into byte code by the WAP gateway and then sent to the micro-browser for interpretation.

    Simple Example
    <?xml version="1.0"
     <!DOCTYPE wml PUBLIC "
     -//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml_1.3.xml"
     <card id="Line" 
     title="First WMLScript"
      <onevent type="onenterforward"
        <go href="ashish.wmls#hello()" 
          <p> $message </p>
    11: </wml>
    This is a WML page (not WMLScript) containing only one card. Inside this card, an event with type onenterforward (lines 6) is defined so that when the card is loaded, the following action is activated.
    <go href="ex21-16.wmls#hello()" />
    Example: ashish.wmls - WMLScript File For ashish.wml
    1: extern function hello()
    2: {
    3:   WMLBrowser.setVar( "message",
    4:      "Hello World! \n I know WMLScript now." );
    5:   WMLBrowser.refresh();
    6: }

    This WMLScript contains one function called hello(). The function is declared as extern (external) so that it can be called by other cards and applications.


    This refresh() function from the WMLBrowser object is to refresh the WML page ashish.wml so that the message is displayed. A screen shot is shown in Fig.

    WMLScript Tutorials
    WMLScript Examples
    WMLScript Interview Materials