O'Reilly logo

Learning WML, and WMLScript by Martin Frost

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The <anchor> Element

While the <do> element is useful, it isn’t always what you want. Many cell phone browsers put all the <do> items in a card in a single menu, which means you can’t guarantee it will appear where you want it to. Sometimes you want to make some of the text into an HTML-style link, rather than have a separate <do> control next to it. For example, if you have a menu of other pages available, you want the items in the menu to display in the correct order, as in Figure 4.1.

Menu of available pages

Figure 4-1. Menu of available pages

Almost all web pages use hyperlinks : text or images that can be activated to go to another page. Web browsers usually display these links underlined or in a different color so the user knows it’s “clickable.” These links are put into a web page with HTML’s <A> tag.

WML also has hyperlinks. As you might expect from the other user interaction elements you’ve seen in this chapter, they aren’t limited to simply going to another place. WML hyperlinks use tasks to allow them to control just about anything useful.

Hyperlinks are put into a page using the <anchor> element. It takes only one attribute:

title (optional variable string)

Provides an optional title to the element. As with the label attribute on the <do> element, you should try to keep this to six or fewer characters, and the browser is free to ignore it. This is rarely used in practice, as there is already the linked text inside the <anchor> to provide a label.

The <anchor> element must contain two things: a task element that is performed when the element is activated and some text or images to which to attach the link. A simple example of the <anchor> element is:

<anchor>next page<go href="page17.wml"/></anchor>

This attaches a link to the words next page, so that selecting them sends the browser to the URL page17.wml.

The most common tasks to use with <anchor> elements are <go> tasks. For other kinds of tasks, consider using <do> elements instead. For example, if you want a control to activate a <prev> task, you should strongly consider simply using a <do> with type set to prev. It’s best to use <anchor> only where it’s important that the control is kept with the text surrounding it.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required