2. Hello World
effective way to learn a new language is to go through examples. The
following "Hello World" WMLScript example shows you how a
WMLScript file typically looks like and demonstrates how to call
WMLScript code in a WML document.
<!DOCTYPE wml PUBLIC
"-//WAPFORUM//DTD WML 1.3//EN"
is the file that contains the WMLScript code:
"Hello World. Welcome to our WMLScript
the helloWorldEg1.wml file
in a mobile phone browser and you can see something like this:
Mobile Browser 4.0
you select the "Run WMLScript" link, the WMLScript function
helloWorld() is executed and
the line "Hello World. Welcome to our WMLScript tutorial."
will appear in the mobile phone browser.
Mobile Browser 4.0
the above example, the WMLScript code is not embedded in the WML
markup and they are kept in separate files. This is the rule of
WMLScript and you need to follow this when programming mobile
Internet browsing applications.
is only one function, helloWorld(), in the WMLScript file. The
extern keyword is used to specify that the helloWorld()
function is allowed to be called from outside the WMLScript file
helloWorldEg1.wmls. The extern keyword is necessary
here since we want to call the function from the WML file
the helloWorld() function, we use two functions of the
WMLBrowser standard library, setVar() and refresh().
The setVar() function is used to assign a value to a WML
variable. We use the WMLScript code:
"Hello World. Welcome to our WMLScript tutorial.");
assign the value "Hello World. Welcome to our WMLScript
tutorial." to a WML variable named message.
refresh() function is used to instruct the WAP browser to
refresh the current WML card. In the helloWorld() function,
after we have assigned a value to the message variable, we
make use of the line:
refresh the WML card so that the change made to the message
variable is shown on the screen of the mobile device.
call the WMLScript function helloWorld() in the WML document,
we use the URL below:
is the file that contains the WMLScript code and helloWorld()
is the function to call.
Feedback Form (ExpandCollapse)