Get the current script tag

javascript

Solution

I think you could safely do this, and not in a DOM-ready mode.

var scripts = document.getElementsByTagName("script"),
selfScript = scripts[scripts.length-1];

I would suggest that if you can, put any configurations in another script block.

<script>
  window.attr1 = 'val1';
  window.attr2 = 'val2';
  window.attr3 = 'val3';
</script>
<script src="x.js"></script>

Problem

Possible Duplicate: How may I reference the script tag that loaded the currently-executing script? I wan't implement this configurations options In a script whit this form ``` <script src="x.js" attr1="val1" attr2="val2" attr3="val3"></script> ``` the problem is find the current script tag, and x.js can be in varius paths `fold1/x.js` `fold1/fold2/x.js` `../fold/x.js` etc... I think that is possible because Dojo framework use this approach.

Original source

Related problems