WMLScript » URL » URL.resolve

Syntax:
URL.resolve(baseUrl, relativeUrl)
baseUrl
The mandatory baseUrl is the base URL for a document (resource). It is the URL that all relative URLs must be referenced against to uniquely determine the document's (resource's) location (address).

For example, for DevGuru, the smallest base URL is:

http://www.devguru.com/
relativeUrl
The mandatory relativeUrl is a partial URL that must be referenced in context to the base URL to uniquely specify the location (address) of the document (resource).

For example, this page has a relative URL of:

../wmls_url_resolve.html

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.

Examples

Code:
<?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>
Explanation:

Code for ResolveExample.wml

Language(s): WML
Code:
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");
};
Explanation:

Code for GetBaseExample.wmls

Language(s): WML

See Also: