Getting javascript src location/hostname
<p>Is there any recommended solutions when an embedding a script that will make a callback to the originating source but the js resides in a different domain.  Sometimes other clients would be in a different domain and I can't rely on getting the document or window location.</p>

<p>Currently, I've been using this but not too happy with this solution.</p>

<pre><code>var host = window.location.hostname;
if(host.indexOf('.devols.') &gt; -1){
  return (('https:' == document.location.protocol) ? 'https://' : 'http://') + host; // return dev or localhost
} else if(host.indexOf('.qaols.') &gt; -1){
  return 'qa environment';        
} else {
  return 'prod environment';
}
</code></pre>

<p>Update:</p>

<p>So far I've been playing around with this:</p>

<pre><code>var scriptLocation = '';
var SCRIPT_NAME = 'example.js';
var scripts = document.getElementsByTagName('script');
for(var i=0;i&lt;scripts.length;i++){
  var src = scripts[i].getAttribute('src');
  if(src){
    var index = src.lastIndexOf(SCRIPT_NAME);
    if((index &gt; -1) &amp;&amp; (index + SCRIPT_NAME.length == src.length)) {
      scriptLocation=src.slice(0, src.indexOf('/my_script_location/'));
      break;
    }
  }
}
return scriptLocation;
</code></pre>

<p>So after the page loads the code cycles thru the script tag array and determines the location so the api can make a callback without having to figure out the urls and etc...</p>
