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

前端 未结 22 1137
南方客
南方客 2020-11-21 22:38

I would like to take a string

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

and process it into an object such that

a.hostname == \         


        
22条回答
  •  天涯浪人
    2020-11-21 23:17

    Use https://www.npmjs.com/package/uri-parse-lib for this

    var t = parserURI("http://user:pass@example.com:8080/directory/file.ext?query=1&next=4&sed=5#anchor");
    

提交回复
热议问题