title: How to get part of URL in JavaScript?
body: <p>What's wrong with this? I want to output only <code>www.google.com</code>.</p>
  
  <pre><code> &lt;script type="text/javascript"&gt; window.onload=function() {  
    var links = document.getElementsByTagName("a");   
     for (var i=0, n=links.length;i&lt;n;i++) {      
       var string = links[i];     
       var str = string;  
       document.write(string);    
       var spl = string.split("/");   
       document.write(spl[2]);       
    } 
  
    } 
  
    &lt;/script&gt; 
  
    &lt;a href="http://www.google.com"&gt;google&lt;/a&gt;&lt;/br&gt; 
  </code></pre>