0

In my

www.my-site.com/index.html 

there is a script tag

<script src="https://api.3rd-pary-site.com/some/path/js/foo.js"></script>

How can code in foo.js get to the "https://api.3rd-pary-site.com/some/path/js/foo.js" ?

pero
  • 4,169
  • 26
  • 27
  • 1
    See the linked question's answers for how to access the `script` element for the currently-running script. Then just get its `src` property value: `var url = document.currentScript && document.currentScript.src;` I have the guard in there to handle really old browsers that don't support it (if there are any). Note that this has to be in code at the top level of the script, not in an async callback. More: https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript – T.J. Crowder Aug 06 '19 at 11:52
  • 1
    Yes. I think that will work. Thanks! – pero Aug 08 '19 at 14:30

0 Answers0