0

I have a js script file being loaded async from a function inside an html file. This has been done in a way which make me out of control of any <script> id, which mean I am NOT able to use getElementById. The script file being loaded is:

<path to file>/my_script.js?name=23

What I would like to do is to parse the 'name' inside the script file at the moment the file is being loaded. I have full control over the script file but no control over the html file. Is it possible for the script to get hold in this name - not using getElementById or getElementByName?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Per Mikkelsen
  • 1,087
  • 1
  • 7
  • 5
  • 1
    Tbh I don't understand what are you trying to achieve. – Dan Macak Mar 01 '19 at 19:47
  • You could add the entire tag to the post, but most likely you need a reference to the currently running script: https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript . If you need to support IE, use [`document.scripts`](https://developer.mozilla.org/en-US/docs/Web/API/Document/scripts) collection. – Teemu Mar 01 '19 at 19:48
  • I am trying to read the parameter 'name' inside the my_script.js file – Per Mikkelsen Mar 01 '19 at 19:49
  • @PerMikkelsen you would have to store the `name` globally in the `window` object somewhere inside this function in the document. Or the server would have to take the name and somehow include it in the response, that means in the script which is returned. – Dan Macak Mar 01 '19 at 19:57

0 Answers0