15.3. Getting the Current WML Card's URL: getCurrentCard() Function
The getCurrentCard() function is used to get the current card's URL address. The URL returned will be in the relative form if the URL base of the current WML file and that of the current WMLScript file are the same, otherwise the URL returned will be in the absolute form.
If there is no current card or if there is an error, then getCurrentCard() returns invalid.
The following example illustrates how to use the getCurrentCard() function. Let's say there is a WML document tutorial_wml_eg.wml that contains the markup below:
<card
id="card1" title="Card 1">
<p>
<a
href="tutorial_wmlscript_eg.wmls#func1()">Run
WMLScript</a>
</p>
</card>
If the "Run WMLScript" anchor link is selected, the func1() function in the tutorial_wmlscript_eg.wmls file will be executed. Let's say the code of the func1() function is:
extern
function func1()
{
var url_str =
WMLBrowser.getCurrentCard();
}
func1 contains one line of code. If it is executed, the url_str variable will contain the string value "tutorial_wml_eg.wml#card1". Note that the relative URL returned is relative to the URL base of the current WMLScript file.
To transform the relative URL into the absolute form, we need to know the URL base of the current WMLScript file. The getBase() function of the URL standard library can help us achieve this. For example, suppose we call the getBase() function in the tutorial_wmlscript_eg.wmls file and the value returned from it is "http://www.developershome.com/examples/wmlscript/tutorial_wmlscript_eg.wmls". Then the absolute URL address of the current WML card is "http://www.developershome.com/examples/wmlscript/" + "tutorial_wml_eg.wml#card1" (the value returned by the getCurrentCard() function).
If the URL of the current WML card contains query parameters (for example "tutorial_wml_eg.wml?x=abc&y=123#card1"), they can be extracted using the getQuery() function of the URL standard library.
Previous Page | Page 33 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