title: Javascript Get Hostname of File Host
body: <p>Although <a href="https://stackoverflow.com/questions/1368264/get-host-name-in-javascript">this question is similar</a>, it is not what I am looking for.</p>
  <p>Let's say on HostA.com I include a script from HostB.com:</p>
  <pre><code>&lt;script type=&quot;text/javascript&quot; src=&quot;http://www.hostb.com/script.js&quot;&gt;
  </code></pre>
  <p>When <strong>script.js</strong> runs, I need to get the name of HostB (let's assume it can change). If I use:</p>
  <pre><code>var hostName = window.location.hostname;
  </code></pre>
  <p>It will return <strong>HostA.com</strong> rather than <strong>HostB.com</strong> obviously because that is where the the <code>window</code> object is scoped.</p>
  <p>How can I get the name of HostB from within the script? Do I have to locate the <code>&lt;script&gt;</code> element in the DOM and parse the <code>src</code> attribute or is there a better way?</p>
  <h1><strong>EDIT</strong></h1>
  <p>Yes, it is on my server, but may be on other servers as well. I am developing a javascript plugin and am trying to make absolute paths so it doesn't try to reference files on the server including the plugin.</p>