20. WMLScript URL Standard Library

WMLScript's URL standard library contains functions for manipulating URLs.

In the following sections, we will look at some of the more commonly used functions in the URL standard library.


20.1. Getting the Current WMLScript Document's URL: getBase() Function

The getBase() function of the URL standard library is used to get the current WMLScript document's URL without the fragment part (the fragment of a URL is the part that begins with the # character). Note that the URL returned is always in the absolute form.

The following WML/WMLScript example demonstrates the use of the getBase() function. Let's say we have a WML document that contains the markup below:


<card id="card1" title="Card 1">
  <p>
    <anchor>
      <go method="get" href="tutorial_eg.wmls#func1()">
        <postfield name="x" value="abc"/>
        <postfield name="y" value="123"/>
      </go>
      Run WMLScript
    </anchor>
  </p>
</card>


If we open the WML card in a WAP browser and select the "Run WMLScript" anchor link, the func1() function in the WMLScript file tutorial_eg.wmls will be executed. Below shows the script included in the tutorial_eg.wmls file:


extern function func1()
{
  var url_str = URL.getBase();
}


func1() contains only a single line of statement. After the statement is executed, the url_str variable has the string value "http://www.developershome.com/examples/wmlscript/tutorial_eg.wmls?x=abc&y=123". (Suppose the tutorial_eg.wmls file is stored in the directory "examples/wmlscript/" of the host "www.developershome.com".)

We can further extract the query string in the url_str variable using the getQuery() function, which will be covered in this tutorial later.


Previous Page Page 62 of 71 Next Page


Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.

A button for going back to the top of this page