Write JS var into html header script source

80 views Asked by At

putting a var into the html isn't that difficult and I found many examples. But it seems I have a special task...

At the beginning of an html file I define a js var with a name of a javascript file. Further down I load all the other JS files by this:

<script src="jss/blah.js"></script>

What I need is to put the content of a js var into this line like this:

<script src="jss/#here-comes-my-JS-var#.js"></script>

I tried several ways without success. Is that not possible?

1

There are 1 answers

2
Volod On

Try something like this:

var yourVars = 'somePathOrWhatever';
var scriptToInclude = document.createElement('script');
scriptToInclude.setAttribute('src','jss/' + yourVars + '.js');
document.head.appendChild(scriptToInclude);