Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Identifying the script element

    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.

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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:
    Code:
    functionName(whateverYouWantToSendToTheScriptThatRequestedThisScript);
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    New Coder
    Join Date
    Feb 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •