home

Softsteel Solutions

About Us Contact Us Newsletter Training
Tutorials
 

Lesson 6: Creating hyperlinks to other pages

This lesson covers navigation between WML cards. As with HTML, navigation is supported by the a tags

<a></a>

The main attribute of these a tags is the 'href' attribute, which specifies the hyperlink target of the anchors. For example:

<a href="target">text</a>

When navigating between cards in the same deck, targets are specified using a '#' before the card's id value. The following script provides an example of two cards which link to each other in this way.

1.

<?xml version="1.0"?>

2.

<!DOCTYPE wml PUBLIC
"-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

3.

<wml>

4.

<card id="card1" title="Welcome">

5.

<p>

6.

Here is a link to<br/>

7.

<a href="#card2" title="Card2">Card 2</a>

8.

</p>

9.

</card>

10.

<card id="card2" title="Card 2">

11.

<p>

12.

Here is a link back to the<br/>

13.

<a href="#card1">Welcome Page.</a><br/> (Card1)

14.

</p>

15.

</card>

16.

</wml>

As can be seen from this script, anchors can also take a value for the 'title' attribute (the value defaults to 'link'). Devices use this attribute in different ways; for instance, the Phone.com device makes it the value of the 'accept' key. Note that to ensure compatibility with different browsers, the title value should be a maximum of 5 characters.

The pictures below demonstrate how this code looks in the development kit browsers from Phone.com and Nokia.

Demonstration of the effects of the code in the phone.com browser

phone.com

Demonstration of the effects of the code in the Nokia browser

Nokia

To navigate from a card to another card outside its deck, one gives the URL of the deck, plus '#' plus the card's id. For instance, the following code describes a link to the card named 'card1', found in the local file 'example7.wml'.

<a href="example7.wml#card1" title="ex7">example 7</a>

The next example describes a link to a card named 'card2', found in a remote file:

<a href="http://wap.example.com/files/index.wml#card2">link</a>

If no id specification is given after a URL, the browser pulls out the first card in the given deck.

 

WML Tutorials