iseehg
Last Updated: February 25, 2016
·
783
· chinchang
6be4e636e8aacd405bed5cd15124a875

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...
Say Thanks
Respond