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:

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.

What do you think about this web page? It is very helpful. It is helpful, but some information I wanted is missing. It is not helpful. It has broken links. It has typos / grammatical mistakes. It has incorrect information. Others

(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:

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