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
a.host; // The host
...

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

Source:
https://html.spec.whatwg.org/multipage/semantics.html#the-a-element

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