WMLScript Standard Libraries: The URL Library - Part II | WebReference

WMLScript Standard Libraries: The URL Library - Part II


WMLScript Standard Libraries

The URL Library - Part II

Here are the rest of the URL library functions:

getQuery()

This function returns the query part used in the given URL. An empty string is returned if no queries are specified. invalid is returned if the URL is invalid.

Syntax getParameters
Parametersurl = String
ReturnsString or invalid
Examples: var a = URL.getQuery("http://www.docjavascript.com/tips;message?m=5&n=3"); // a = "m=5&n=3"

getFragment()

This function returns the fragment used in the given URL. An empty string is returned if no fragments are specified. invalid is returned if the URL is invalid.

SyntaxgetFragment(url)
Parametersurl = String
ReturnsString or invalid
Examples:var a = URL.getFragment("http://www.docjavascript.com/tips#myTip"); // a = "myTip"

getBase()

This function returns the absolute URL (without the fragment) of the current WMLScript compilation unit.

SyntaxgetBase()
Parametersnone
ReturnsString
Examples:var a = URL.getBase(); // a = "http://www.docjavascript.com/wireless/mortgage.scr"

getReferer()

This function returns the smallest relative URL (relative to the base URL of the current compilation unit) to the resource that called the current compilation unit. An empty string is returned if no referer exists.

SyntaxgetReferer()
Parametersnone
ReturnsString
Examples:var a = URL.getReferer(); // a = "mortgage.wml#card2"

resolve()

This function returns an absolute URL from the given base and relative URL.

Syntaxresolve(baseUrl, relativeUrl)
ParametersbaseUrl = String, relativeUrl = String
ReturnsString or invalid
Examples:var a = URL.resolve("http://www.docjavascript.com", "/wireless/mortgage.scr"); // a = "http://www.docjavascript.com/wireless/mortgage.scr"

escapeString()

This function returns the given URL where special characters have been replaced by a hexadecimal escape sequence (%XX). invalid is returned if given string contains characters above FF code. These are the escaped characters:

Control charactersASCII codes 00-1F and 7F
SpaceASCII code 20 hexadecimal
Reserved";", "/", "?", ":", "@", "&", "=", "+", "$", ","
Avoid"{", "}", "|", "\", "^", "[", "]", "`"
Delimiters"", "#", "%",
Non ASCIIcharacters with hex codes 8F-FF

Here is a summary of the escapeString() function:

SyntaxescapeString(url)
Parametersurl = String
ReturnsString or invalid
Examples:var a = URL.escapeString("http://www.docjavascript.com/wireless/mortgage.scr"); // a = "http%3a%2f%2fwww.docjavascript.com%2fwireless%2fmortgate.scr"

unescapeString()

This function returns the given URL where escape sequences have been replaced by the appropriate characters. invalid is returned if the given string contains non-ASCII characters.

SyntaxescapeString(string)
Parametersstring = String
ReturnsString or invalid
Examples:var a = URL.unescapeString("http%3a%2f%2fwww.docjavascript.com%2fwireless%2fmortgate.scr"); // a = "http://www.docjavascript.com/wireless/mortgate.scr"

loadString()

This function returns the content denoted by the given URL and the content type. The syntax is loadString(url, contentType). The contentType argument must begin with "text/", and must not have any leading or trailing spaces. The content is loaded by this call. If the load is successful and the returned content type matches the given argument, the content is converted to a string and returned. If the load is not successful or the returned content is of a wrong type, an error code is returned. The error code depends on the used URL scheme. invalid is returned if the contentType argument is erroneous.

SyntaxloadString(url, contentType)
Parametersurl = String, contentType = String
ReturnsString, Integer, or invalid
Examples:var a = URL.loadString("http://www.docjavascript.com/wireless/mortgate.scr", "text/x-vcard");

Next: How to use WMLBrowser library

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

Created: June 5, 2000
Revised: June 5, 2000

URL: http://www.webreference.com/js/column63/8.html