Created
March 18, 2011 12:14
-
-
Save zela/875951 to your computer and use it in GitHub Desktop.
url parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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