This is why JavaScript is awesome

Loved this gist from John W. Long.

var parser = document.createElement('a');
parser.href = 'http://example.com:3000/pathname/?search=test#hash';
parser.protocol; // 'http:'
parser.hostname; // 'example.com'
parser.port; // '3000'
parser.pathname; // '/pathname/'
parser.search; // '?search=test'
parser.hash; // '#hash'
parser.host; // 'example.com:3000'

If you like my content, please consider buying me a coffee.

Buy Me A Coffee

comments powered by Disqus