Possible Duplicate:
How may I reference the script tag that loaded the currently-executing script?
Can you select the script element that included the JavaScript?
Is there any identifyScript that could make this work? jQuery is cool too.:
<script type="text/javascript" id="script1">
function identifyScript(){...}
</script>
<script type="text/javascript" id="script1">
identifyScript(); //This function would alert "script1"
</script>
<script type="text/javascript" id="script2">
identifyScript(); //This function would alert "script2"
</script>
As long as it is guaranteed that the script files are getting loaded sequentially (which means, not asyncronously), you can call the following code within each javascript file:
However, this concept breaks as soon as there is an
asyncordeferattribute within those<script>elements. Each of these attributes allows the browser to delay the loading of scripts and order is no longer guaranteed.But if you’re loading your files without any async flags, this will work just fine because each script accesses the last inserted
<script>node, which must be the one it was loaded from.