title: Parsing url in javascript or angularjs
body: <p>I'm trying to parse url in javascript, I found the following way:</p>
  
  <pre><code>var getLocation = function(href) {
      var l = document.createElement("a");
      l.href = href;
      return l;
  };
  var l = getLocation("http://example.com:3000/path");
  var host = l.host; // example.com
  var port = l.port; // 3000
  </code></pre>
  
  <p>But I faced a problem if these locations:</p>
  
  <pre><code>http://TLVS0015:3000/cti/YTest // the parse found the port, but its not found the host
  
  http://ctmwe:80/ReportServer/ReportService2010.asmx // the parse found the host, but don't found the port
  </code></pre>
  
  <p>Is there any other way to do the parse?</p>