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

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.

SyntaxisValid(url)
Parametersurl = String
ReturnsBoolean or invalid
Examples:var a = URL.isValid("https://www.docjavascript.com"); // a = true
var b = URL.isValid("https://www.docjavascript.com?"); // b = false
var 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.

SyntaxgetScheme(url)
Parametersurl = String
ReturnsString or invalid
Examples:var a = URL.getScheme("https://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.

SyntaxgetHost(url)
Parametersurl = String
ReturnsString or invalid
Examples:var a = URL.getHost("https://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.

SyntaxgetPort(url)
Parametersurl = String
ReturnsString or invalid
Examples:var a = URL.getPort("https://www.docjavascript.com:80/tips"); // a = "80"
var b = URL.getPort("https://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.

SyntaxgetPath(url)
Parametersurl = String
ReturnsString or invalid
Examples:var a = URL.getPath("https://www.docjavascript.com:80/tips/000531.html"); // a = "/tips/000531.html"
var b = URL.getPath("https://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.

SyntaxgetParameters(url)
Parametersurl = String
ReturnsString or invalid
Examples:var a = URL.getParameters("https://www.docjavascript.com/tips;message"); // a = "message"
var b = URL.getParameters("https://www.docjavascript.com/tips;a/000531.html;myTip"); // b = "myTip"

Next: How to use URL library - Part II

https://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

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

URL: https://www.webreference.com/js/column63/7.html