2

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 =)

1

2 Answers 2

4

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

Here is your example

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.