get external file source (location) using javascript
I insert an external .js file from another domain. Like this:
<script src="http://externaldomain.com/file.js" type="text/javascript"></script>
file.js is always the same, but it can be placed in different domains,
so I need to know what is the source of the file.
Fo开发者_C百科r example: file.js is in domain1.com, domain2.com and domain3.com.
If someone insert it like this: <script src="http://domain1.com/file.js" type="text/javascript"></script>
I want to know that the file is inserted from domain1.com
How to do it?
There's no reliable way of achieving this. Basically inside this file you will need to parse the DOM, search for all the <script>
tags and when you find the one that corresponds to the inclusion of this javascript file parse the src
attribute to extract the domain.
精彩评论