Question regarding how to dynamically change external javascript source information

V

vfpuglia

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
 
R

RobG

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

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"
 
P

pcx99

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

<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!
 
R

Randy Webb

RobG said the following on 2/8/2007 9:07 PM:
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
[...]
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.

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"


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

Hmmm :)
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top