Get domain of Javascript file

So I have a site at http://mysite.com/ and I have a Javascript file on a CDN, the Javascript file could be at http://cdn1.mysite.com/ or http://cdn2.mysite.com/, I need to get the value of the hostname the javascript file is on. Is there any way to do this? I cannot modify the embed code of the javascript file to add a custom ID or add an additional variable on mainsite.com.

The reasons why I need this are far too complicated for one post =)

Answers:

Answer

You can get all the scripts you are loading in your page and search by name for the right one

Here is your example

Answer

If you know the index of the embedded <script> inside document.getElementsByTagName('script') you may read the src-attribute of the <script> and extract the hostname from that src.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.