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...Written by Kushagra Gour
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Parse
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#