iseehg
Last Updated: February 25, 2016
·
800
· chinchang

Get URL parts without regex

Here is a neat trick I found on Stackoverflow to get parts of any URL without using regex:

var a = document.createElement('a');
a.href = url;

// Get parts easily now:
console.log(a.host);
console.log(a.hostname);
// and so on...