spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column63


WMLScript Standard Libraries

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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("http://www.docjavascript.com"); // a = true
var b = URL.isValid("http://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("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.

SyntaxgetHost(url)
Parametersurl = String
ReturnsString 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.

SyntaxgetPort(url)
Parametersurl = String
ReturnsString 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.

SyntaxgetPath(url)
Parametersurl = String
ReturnsString 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.

SyntaxgetParameters(url)
Parametersurl = String
ReturnsString 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

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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

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