WMLScript Standard Libraries: The URL Library - Part I
WMLScript Standard Libraries
The URL Library - Part I
This library contains functions for handling absolute and relative URLs.
isValid()
This function returns true if the given URL has the right syntax, false otherwise.
| Syntax | isValid(url) |
| Parameters | url = String |
| Returns | Boolean or invalid |
| Examples: | var a = URL.isValid("http://www.docjavascript.com"); // a = truevar b = URL.isValid("http://www.docjavascript.com?"); // b = falsevar c = URL.isValid("http>://www.docjavascript.com"); // c = false |
getScheme()
This function returns the scheme used in the given URL. Invalid URLs cause a return of invalid.
| Syntax | getScheme(url) |
| Parameters | url = String |
| Returns | String or invalid |
| Examples: | var a = URL.getScheme("http://www.docjavascript.com"); // a = "http"var b = URL.getScheme("ftp://www.docjavascript.com"); // b = "ftp"var c = URL.getScheme("www.docjavascript.com"); // c = "" |
getHost()
This function returns the host specified in the given URL. An empty string is returned if no host is specified.
| Syntax | getHost(url) |
| Parameters | url = String |
| Returns | String or invalid |
| Examples: | var a = URL.getHost("http://www.docjavascript.com/tips"); // a = "www.docjavascript.com"var b = URL.getHost("/js/tips"); // b = "" |
getPort()
This function returns the port number specified in the given URL. An empty string is returned if no port is specified.
| Syntax | getPort(url) |
| Parameters | url = String |
| Returns | String or invalid |
| Examples: | var a = URL.getPort("http://www.docjavascript.com:80/tips"); // a = "80"var b = URL.getPort("http://www.docjavascript.com/tips"); // b = "" |
getPath()
This function returns the path specified in the given URL. An empty string is returned if no path is specified.
| Syntax | getPath(url) |
| Parameters | url = String |
| Returns | String or invalid |
| Examples: | var a = URL.getPath("http://www.docjavascript.com:80/tips/000531.html"); // a = "/tips/000531.html"var b = URL.getPath("http://www.docjavascript.com/column35/game.html#true"); // b = "/column35/game.html" |
getParameters()
This function returns the parameters used in the last path segment of the given URL. An empty string is returned if no parameters are specified. invalid is returned if the URL is invalid.
| Syntax | getParameters(url) |
| Parameters | url = String |
| Returns | String or invalid |
| Examples: | var a = URL.getParameters("http://www.docjavascript.com/tips;message"); // a = "message"var b = URL.getParameters("http://www.docjavascript.com/tips;a/000531.html;myTip"); // b = "myTip" |
Next: How to use URL library - Part II
Produced by Yehuda Shiran and Tomer Shiran
Created: June 5, 2000
Revised: June 5, 2000
URL: http://www.webreference.com/js/column63/7.html


