View Full Version : Identifying the script element

02-02-2006, 12:18 PM
I'm in the middle of a slightly surreal bit of AJAX experimentation, which involves, amongst many other things, the dynamic loading / unloading of javascript, sans page reloads.

Now leaving aside, for the moment, the discussion on whether or not this is actually a good idea...

When loading a js file using:
<script type="text/javascript" src="/folder/script.js"></script>

Is it possible for the script running in script.js to be able to identify the <script> element that is loading it, and to access it as an object? I have my suspicions that it isn't possible... but if it is, it would be extremely useful to me.

02-02-2006, 01:09 PM
It's not possible, no. However, if you have a serverside langauge you can do it like this:

Add a script with the filename "blah.js?fn=functionName".

This script defines what globals it needs, and then runs the code:

02-02-2006, 03:23 PM
You know... that's a fantastic idea? In this case, I can do it clientsite, rather than serverside, given the nature of the app - but this should let me do exactly what I need - thanks!