Question regarding how to dynamically change external javascript source information

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

  1. vfpuglia

    vfpuglia Guest

    Hi,

    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

    <script>

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

    //build the src destination w/ the keywords
    var $myURL;
    $myURL = "http://www.foo.com/?keyword=";
    $myURL += qsParm['keyword'];

    </script>

    ..
    ..
    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

    Thanks!
    Vince
     
    vfpuglia, Feb 8, 2007
    #1
    1. Advertisements

  2. vfpuglia

    RobG Guest

    A couple of recent threads that might help:

    "Dynamic Script Insertion & caching"
    <URL: http://groups.google.com.au/group/comp.lang.javascript/
    browse_frm/thread/8b6d226964e7ffc9/40c7b03d03a4af28?lnk=gst&q=dynamic
    +script+insertion&rnum=1#40c7b03d03a4af28 >

    "createTextNode and IE7"
    <URL: http://groups.google.com.au/group/comp.lang.javascript/
    browse_frm/thread/7e23f42490c301de/32362b99328a2adb?lnk=gst&q=dynamic
    +script+insertion&rnum=5#32362b99328a2adb >

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

  3. vfpuglia

    pcx99 Guest

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

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

    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)
    http://www.hunlock.com/blogs/Howto_Dynamically_Insert_Javascript_And_CSS

    Good luck!
     
    pcx99, Feb 9, 2007
    #3
  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
    #4
    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.