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 |
Parameters | url = String |
Returns | String or invalid |
Examples: | var a = URL.getQuery("https://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.
Syntax | getFragment(url) |
Parameters | url = String |
Returns | String or invalid |
Examples: | var a = URL.getFragment("https://www.docjavascript.com/tips#myTip"); // a = "myTip" |
getBase()
This function returns the absolute URL (without the fragment) of the current WMLScript compilation unit.
Syntax | getBase() |
Parameters | none |
Returns | String |
Examples: | var a = URL.getBase(); // a = "https://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.
Syntax | getReferer() |
Parameters | none |
Returns | String |
Examples: | var a = URL.getReferer(); // a = "mortgage.wml#card2" |
resolve()
This function returns an absolute URL from the given base and relative URL.
Syntax | resolve(baseUrl, relativeUrl) |
Parameters | baseUrl = String, relativeUrl = String |
Returns | String or invalid |
Examples: | var a = URL.resolve("https://www.docjavascript.com", "/wireless/mortgage.scr"); // a = "https://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 characters | ASCII codes 00-1F and 7F |
Space | ASCII code 20 hexadecimal |
Reserved | ";", "/", "?", ":", "@", "&", "=", "+", "$", "," |
Avoid | "{", "}", "|", "\", "^", "[", "]", "`" |
Delimiters | "", "#", "%", |
Non ASCII | characters with hex codes 8F-FF |
Here is a summary of the escapeString()
function:
Syntax | escapeString(url) |
Parameters | url = String |
Returns | String or invalid |
Examples: | var a = URL.escapeString("https://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.
Syntax | escapeString(string) |
Parameters | string = String |
Returns | String or invalid |
Examples: | var a = URL.unescapeString("http%3a%2f%2fwww.docjavascript.com%2fwireless%2fmortgate.scr"); // a = "https://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.
Syntax | loadString(url, contentType) |
Parameters | url = String, contentType = String |
Returns | String, Integer, or invalid |
Examples: | var a = URL.loadString("https://www.docjavascript.com/wireless/mortgate.scr", "text/x-vcard"); |
Next: How to use WMLBrowser library
Produced by Yehuda Shiran and Tomer Shiran
Created: June 5, 2000
Revised: June 5, 2000
URL: https://www.webreference.com/js/column63/8.html