How to Parse a URL in JavaScript
Sure there are plugins that will do this for you, but here's a quick and easy way.
Posted in these interests:
Sure there are plugins that will do this for you, but here's a quick and easy way.
Create an "a" tag and set the href to the URL you want to parse:
var parser = document.createElement("a");
parser.href = "http://howchoo.com:8000/interests?query=1#bottom";
Now use the parser object to get the URL parts:
parser.protocol; // =>"http:"
parser.hostname; // => "howchoo.com"
parser.port; // =>"8000"
parser.pathname; // => "/interests"
parser.search; // => "?query=1"
parser.hash; // => "#bottom"
parser.host; // => "howchoo.com:8000"
This article expands on this idea to provide a little more functionality.
Nothing says good morning quite like a breakfast sandwich. From the doughiness of the muffin to the eggs' fluffiness to the cheese's gooeyness, breakfast sandwiches are a great start to your morning.