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 |
- 1. WMLScript Introduction
- 2. Hello World WMLScript Example
- 3. Compiling WMLScript Code
- 4. WMLScript Language Rules
- 5. Defining WMLScript Functions
- 6. Calling WMLScript Functions
- 7. WMLScript Variables
- 8. WMLScript Data Types
- 9. WMLScript Variables Vs WML Variables
- 10. Passing Arguments to Functions By Value and By Reference
- 11. WMLScript Operators
- 12. WMLScript Conditional Statements
- 13. WMLScript Looping Statements
- 14. WMLScript Standard Libraries Overview
- 15. WMLScript WMLBrowser Standard Library
- 16. WMLScript Dialogs Standard Library
- 17. WMLScript String Standard Library
- 18. WMLScript Float Standard Library
- 19. WMLScript Lang Standard Library
- 20. WMLScript URL Standard Library
- 21. WMLScript Example: Validating Form Data