I have an external JavaScript file that is stored at: http://example.com/script.js. I'd like to extract out http://example.com from inside the JavaScript file. The only problem is that I'm embedding the JavaScript file in a website with a different domain. I've looked into using window.location
but that will return the url of the page that has embedded the JavaScript instead of the url that's hosting the script.
example.com/script.js
var hostingUrl = window.location.origin;
alert(hostingUrl);
anotherdomain.com
<!-- This will alert: 'anotherdomain.com' instead of: 'example.com' -->
<script src="http://example.com/script.js"></script>