WMLScript » URL » URL.resolve

URL.resolve(baseUrl, relativeUrl)
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:

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:


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"?>

<card id="card1">
   getBase example
   <do type="accept">
      <go href="ResolveExample.wmls#findresolve()" />

<card id="card2">
   base URL = $(baseurl)
   <br />
   relative URL = $(relativeurl)
   <br />
   resolved URL = $(resolvedurl)


Code for ResolveExample.wml

Language(s): 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);

Code for GetBaseExample.wmls

Language(s): WML

See Also: