The URL library contains a set of functions for handling absolute URLs and relative URLs. The general URL syntax is:
<scheme>://<host>:<port>/<path>;<params>?<query>#<fragment>
For more information, visit:
http://info.internet.isi.edu/in-notes/rfc/files/rfc2396.txt
Included in this section are the following function calls:
url.escapeString(string)
This function computes a new version of a string value in which special characters have been replaced by a hexadecimal escape sequence; a two-digit escape sequence of the form %xx must be used. For more information, visit:
http://info.internet.isi.edu/in-notes/rfc/files/rfc2396.txt
The characters to be escaped are:
|
Control characters |
<US-ASCII coded characters 00-1F and 7F>
|
|
Space |
<US-ASCII coded character 20 hexadecimal>
|
|
Reserved |
; / ? : @ & = + $ ,
|
|
Unwise |
( ) | \ ^ [ ] '
|
|
Delims |
< > # % "
|
The given string is escaped as such. No URL parsing is performed.
string = String
String or invalid.
If string contains characters that are not part of the US-ASCII character set, an invalid value is returned.
var a = URL.escapeString("http://w.h.com/dck?x=\u007f#crd");
// a = "http%3a%2f%2fw.h.com%2fdck%3fx%3d%7f%23crd"
url.getBase()
Returns an absolute URL (without the fragment) of the current WMLScript 1.1 file.
String
var a = URL.getBase();
// a = "http://www.host.com/test.scr"
url.getFragment(url)
Returns the fragment used in the given url. If no fragment is specified, an empty string is returned. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.
url = String
String or invalid.
If an invalid URL syntax is encountered while extracting the fragment, an invalid value is returned.
var a = URL.getFragment("http://w.h.com/cont#frag");
// a = "frag"
url.getHost(url)
Returns the host specified in the given url. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.
url = String
String or invalid.
If an invalid URL syntax is encountered while extracting the host part, an invalid value is returned.
var a = URL.getHost("http://w.h.com/path#frag");
// a = "w.h.com"
var b = URL.getHost("path#frag");
// b = ""
url.getParameters(url)
Returns the parameters used in the given url. If no parameters are specified, an empty string is returned. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.
url = String
String or invalid.
If an invalid URL syntax is encountered while extracting the parameters, an invalid value is returned.
a = URL.getParameters("http://w.h.com/script;3;27x=1&y=3");
// a = "3;2"
b = URL.getParameters("../script;3;2?x=1&y=3");
// b = "3;2"
url.getPath(url)
Returns the path specified in the given url. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.
url = String
String or invalid.
If an invalid URL syntax is encountered while extracting the path, an invalid value is returned.
a = URL.getPath("http://w.h.com/home/sub/comp#frag");
// a = "3;2"
b = URL.getParameters("../script;3;2?x=1&y=3");
// b = "3;2"
// b = "../home/sub/comp"
url.getPort(url)
Returns the port number specified in the given url. If no port is specified, an empty string is returned. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.
url = String
String or invalid.
If an invalid URL syntax is encountered while extracting the port number, an invalid value is returned.
var a = URL.getPort("http://w.h.com:80/path#frag");
// a = "80"
var b = URL.getPort("http://w.h.com/path#frag");
// b = ""
url.getQuery(url)
Returns the query part specified in the given url. If no query part is specified, an empty string is returned. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.
url = String
String or invalid.
If an invalid URL syntax is encountered while extracting the query part, an invalid value is returned.
a = URL.getParameters("http://w.h.com/home;3;2?x=1&y=3");
// a = "x=1&y=3"
var base = URL.getBase();
// base = "http://www.host.com/current.scr"
url.getReferer()
Returns the smallest relative URL (relative to the base URL of the current file) to the resource that called the current file. Local function calls do not change the referer. If the current file does not have a referer, an empty string ("") is returned.
String
var referer = URL.getReferer();
// referer = "app.wml"
url.getScheme(url)
Returns the scheme used in the given url. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.
url = String
String or invalid.
If an invalid URL syntax is encountered while extracting the scheme, an invalid value is returned.
var a = URL.getScheme("http://w.h.com/path#frag");
// a = "http"
var b = URL.getScheme("w.h.com/path#frag");
// b = ""
url.isValid(url)
Returns true if the given url has the right URL syntax, otherwise returns false. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.
url = String
Boolean or invalid
var a = URL.isValid("http://w.hst.com/script#func()");
// a = true
var b = URL.isValid("../common#test()");
// b = true
var c = URL.isValid("experimental?://www.host.com/cont");
// c = false
url.loadString(url, contentType)
Returns the content denoted by the given absolute url and the content type.
The given content type is erroneous if it does not comply with the following rules:
Only one content type can be specified. The whole string must match with only one content type and no extra leading or trailing spaces are allowed.
The type must be text but the subtype can be anything. Thus, the type prefix must be "text/".
The behavior of this function is the following:
The content with the given content type and url is loaded. The rest of the attributes needed for the content load are specified by the default settings of the user agent.
If the load is successful and the returned content type matches the given content type, the content is converted to a string and returned.
If the load is unsuccessful or the returned content is of wrong content type, a scheme-specific error code is returned.
url = String
contentType = String
String, integer, or invalid.
Returns an integer error code that depends on the used URL scheme in case the load fails. If HTTP or WSP schemes are used, HTTP error codes are returned.
If an erroneous content type is given, an invalid value is returned.
var myUrl = "http://www.host.com/vcards/myaddr.vcf";
myCard = URL.loadString(myUrl, "text/x-vcard");
url.resolve(baseUrl, embeddedUrl)
Returns an absolute URL from the given baseUrl and the embeddedUrl. For more information, visit:
http://info.internet.isi.edu/in-notes/rfc/files/rfc2396.txt
If the embeddedUrl is already an absolute URL, the function returns it without modification.
baseUrl = String
embeddedUrl = String
String or invalid.
If an invalid URL syntax is encountered as part of the resolution an invalid value is returned.
var a = URL.resolve("http://foo.com/","foo.vcf");
// a = "http://foo.com/foo.vcf"
url.unescapeString(string)
The unescape function computes a new version of a string value in which each escape sequence of the sort that might be introduced by the URL.escapeString() function is replaced with the character that it represents. The given string is unescaped as such. No URL parsing is performed.
string = String
String or invalid.
If string contains characters that are not part of the US-ASCII character set, an invalid value is returned.
var a = "http%3a%2f%2fw.h.com%2fdck%3fx%3d12%23crd";
var b = URL.unescapeString(a);
// b = "http://w.h.com/dck?x=12#crd"