Skip to content

Instantly share code, notes, and snippets.

@zela
Created March 18, 2011 12:14
Show Gist options
  • Save zela/875951 to your computer and use it in GitHub Desktop.
Save zela/875951 to your computer and use it in GitHub Desktop.
url parser
function parseURL(url){
var l = document.createElement("a");
l.href = url;
// output object
var o = {
// parts of parsed URL
hash: l.hash,
host: l.host,
hostname: l.hostname,
href:l.href,
pathname: l.pathname,
port: l.port,
protocol: l.protocol,
search: l.search,
// optional output function
out: function(e){
// choose where to write output
if (!e) e = document.body;
if (typeof e === "string") e = document.getElementById(e);
// building list
var ul = document.createElement("ul");
function addLi(s) {
var li = document.createElement("li");
var text = document.createTextNode(s);
li.appendChild(text);
ul.appendChild(li);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment