3

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.

Community
  • 1
  • 1
Rolando Corratge Nieves
  • 1,233
  • 2
  • 10
  • 25
  • Also related: http://stackoverflow.com/questions/6779515/can-you-select-the-script-element-that-included-the-javascript – zzzzBov Oct 31 '12 at 15:40

1 Answers1

5

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>
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • 1
    It's work fine.Is for a script that not use DOM-Ready thanks. All the browser behave in the same way loading the scripts sequentially? or some pararell mode can break this? – Rolando Corratge Nieves Oct 31 '12 at 16:00