Parsing a URL in Javascript

If you want to extract URL information from a link using Javascript, like the host name or the path information, it is as easy as:

var link = ...; // Any URL
var a = document.createElement('a');
a.href = link;
a.pathname; // The path portion; // The host

The trick is that the <a> element implements the Location methods! Neat!


The a element also supports the URLUtils interface. [URL]