Calling WMLScript from WML

At last, here’s the part that tells you how to actually get the browser to call all this WMLScript you’ve been writing!

A function to be called from WML must be declared extern. However, there are no other restrictions on it. It can have as many arguments as you like, and these arguments can be of any type.

Embedding the Function Call in a <go> Task

You call WMLScript from WML by using a <go> task with a specially formatted URL. The function to call and the arguments to pass are encoded into the URL fragment (the part after the first # character). This fragment looks just like a normal WMLScript function call. For example, a call to the function test('foo') in the file referenced by the relative URL test.wmlsc can be written as:

<go href="test.wmlsc#test('foo')"/>

Note that this uses single quotes around the string 'foo'. It can be equally well written as:

<go href='test.wmlsc#test("foo")'/>

It’s probably best to be consistent about using either single or double quotes around all your attribute values and then use the other kind around any strings in the embedded call to WMLScript. For example, I always put double quotes around attribute values, and then always use single quotes around embedded strings, just like the first form of the last call.

The following sections describe differences between how you embed a WMLScript call in a <go> task’s URL and how you would write the call in WMLScript itself.

Variable substitution

Because the call is embedded in ...

Get Learning WML, and WMLScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.