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

前端 未结 22 1131
南方客
南方客 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:30

    The AngularJS way - fiddle here: http://jsfiddle.net/PT5BG/4/

    
    
    
        Parse URL using AngularJS
    
    
    
    

    Parse URL using AngularJS

    url:
    • href = {{parser.href}}
    • protocol = {{parser.protocol}}
    • host = {{parser.host}}
    • hostname = {{parser.hostname}}
    • port = {{parser.port}}
    • pathname = {{parser.pathname}}
    • hash = {{parser.hash}}
    • search = {{parser.search}}

提交回复
热议问题