How to make an external javascript file knows its own host?
<p>Is there any way that in an external javascript file, can know the host of the file?</p>

<p>For example, if I have the site <code>http://hostOne.com/index.php</code>, the code of the file <code>index.php</code>:</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
   &lt;script type="text/javascript" src="http://hostTwo.com/script/test.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
   &lt;div&gt;...&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>I need that in the file <code>test.js</code> can know the host <code>http://hostTwo.com</code>.</p>

<p>Thank you.</p>

<p><strong>EDIT</strong></p>

<p>or it can know the tag "script" which was called?, with this option I can analyzes the tag and get the "src" attribute. But I don't want to depend on the name of the file <code>test.js</code> and analyze all the tag <code>script</code> that contains the site.</p>

<p>*<strong>Solution based on the code of @Armi *</strong></p>

<p>Html:</p>

<pre><code>    &lt;html&gt;
    &lt;head&gt;
      &lt;script class="jsbin"  src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script id="idscript" type="text/javascript" src="http://hostTwo.com/script/test.js"&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
       &lt;div&gt;...&lt;/div&gt;
    &lt;/body&gt;
    &lt;/html&gt;
</code></pre>

<p>code in JS</p>

<pre><code>var 
     url = $('head').find('#idscript').attr('src'),
     host = url.replace(/(\/\/.*?\/).*/g, '$1');

console.log(host);
</code></pre>
