How do I parse a URL into hostname and path in javascript? -


i take string

var = "http://example.com/aa/bb/" 

and process object such that

a.hostname == "example.com" 

and

a.pathname == "/aa/bb" 

var getlocation = function(href) {     var l = document.createelement("a");     l.href = href;     return l; }; var l = getlocation("http://example.com/path"); console.debug(l.hostname) >> "example.com" console.debug(l.pathname) >> "/path" 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -