Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

pass value inside the js file using script tag

I came across an idea as assigning an id to the <script> element and 
passing the arguments as data-* attributes. The resulting <script> tag would 
look something like this:

<script id="helper" data-name="helper" src="helper.js"></script>

The script could then use the id to programmatically locate itself and parse 
the arguments. Given the previous <script> tag, the name could be retrieved 
like this:

var name = document.getElementById("helper").getAttribute("data-name");

We get output name = helper
 
PREVIOUS NEXT
Tagged: #pass #js #file #script #tag
ADD COMMENT
Topic
Name
5+7 =