Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  An alternative way to parse URL in JavaScript

Normally when we need to process URL in JavaScript, we may use the location object. Then we can use location.hostname,location.href,location.port etc to get the information we need. In this post, we will parse an URL with an alternative way.We can use an URL to create a DOM object by calling document.createElement("a"). The complete code is:function parseURL(url) { var a = document.createElement('a'); a.href = url; return { source: url, protocol: a.protocol.replace(':',''), host: a.hostname, port: a.port, query: a.search, params: (function(){ var ret = {}, seg = a.search.replace(/^\?...

11,372 1       URL LOCATION PARSE