Question regarding how to dynamically change external javascript source information

Discussion in 'Javascript' started by vfpuglia, Feb 8, 2007.

  1. vfpuglia

    vfpuglia Guest


    Lets get it out there... I'm a newbie to javascript.

    I'm trying to build a string for the external source file destination
    and be able to change the keywords in the string based on what the
    user presses/inputs. So here is what I have so far


    .... some javascript to get the keyword arguments out of the URL ...

    //build the src destination w/ the keywords
    var $myURL;
    $myURL = "";
    $myURL += qsParm['keyword'];


    some HTML for the page

    <script src=" XXX "></script>

    How do I get the XXX to be my variable that I built up at the top of
    my page? I feel like I've tried everything... If I printout the
    variable to the page - it is correct so its there, just dont know how
    to pass it to src.

    Please help

    vfpuglia, Feb 8, 2007
    1. Advertisements

  2. vfpuglia

    RobG Guest

    A couple of recent threads that might help:

    "Dynamic Script Insertion & caching"
    +script+insertion&rnum=1#40c7b03d03a4af28 >

    "createTextNode and IE7"
    +script+insertion&rnum=5#32362b99328a2adb >

    Search the archives for "dynamic script insert"
    RobG, Feb 9, 2007
    1. Advertisements

  3. vfpuglia

    pcx99 Guest

    var headID = document.getElementsByTagName("head")[0];
    var newScript = document.createElement('script');
    newScript.type = 'text/javascript';
    newScript.src = XXX;

    The moment headID.appendChild is executed the source file you specified
    ( XXX ) will attempt to be loaded, the javascript file compiled and then

    That's pretty much all there is to it. If you'd like to see a few nifty
    things that can be done with this you can check out an article I wrote
    on the subject (warning self promoting link incomming)

    Good luck!
    pcx99, Feb 9, 2007
  4. vfpuglia

    Randy Webb Guest

    RobG said the following on 2/8/2007 9:07 PM:

    document.write('<script src="' + XXX + '"><\/script>')

    Hmmm :)
    Randy Webb, Feb 9, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.