I’m looking for a way to post variables in an external .js file.
Something like:
<script type="text/javascript" src="/js/script-starter.js?var=value"></script>
And then I’d like to call var (and thus, value). Is this possible in any way?
Thank you!
Yes, it is possible. You will have to look for all
scripttags in the DOM (make sure the DOM is loaded before attempting to look in it) using the document.getElementsByTagName function, loop through the resulting list, find the corresponding script and parse thesrcproperty in order to extract the value you are looking for.Something along the lines of:
As far as the parsing of the
srcattribute is concerned and extracting the query string values from it you may use the following function.