Returns an absolute URL given a base and embedded URL.
The URL.resolve
function appends a relative URL to the base URL to create and return an
absolute URL. This is referred to as resolving the URLs.
The exact appending procedure may prove to be very
browser dependent, with some browsers being more efficient at
resolving.
When the two URLs are appended, a
slash / may be added between the two URLs to maintain the correct path
syntax. If the given base URL is the empty string, then the base URL
may be assigned the value of a slash / to maintain the correct path
syntax. If the given relative URL is already an absolute URL, then it
is not appended to the given base URL; rather, the given relative URL
is returned. If the relative URL is the empty string, then the base URL
may be returned.
This function examines the
syntax of both URLs. If either URL is of the wrong syntax,
invalid is returned.
You can use the
URL.getBase function to get the base URL.
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC
"-//WAPFORUM//DTD WML 1.1//EN"
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1">
<p>
getBase
example
</p>
<do type="accept">
<go
href="ResolveExample.wmls#findresolve()" />
</do>
</card>
<card id="card2">
<p>
base URL = $(baseurl)
<br />
relative
URL = $(relativeurl)
<br />
resolved URL = $(resolvedurl)
</p>
</card>
</wml>
Code for ResolveExample.wml
extern function findresolve()
{
var base = Dialogs.prompt("Enter base URL",
"");
var rela = Dialogs.prompt("Enter
relative URL", "");
var reso = URL.resolve(base, rela);
WMLBrowser.setVar("baseurl", base);
WMLBrowser.setVar("relativeurl", rela);
WMLBrowser.setVar("resolveurl", reso);
WMLBrowser.go("ResolveExample.wml#card2");
};
Code for GetBaseExample.wmls