开发者

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 va开发者_Python百科lue 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 =)


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

Here is your example


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜