Click to See Complete Forum and Search --> : Dynamic external Js file


mac-10
10-09-2003, 09:08 AM
Hi there
I am try to change and external js file link I have
almost got it to work

http://www.webpointsolutions.co.uk/help/help.htm

but I don’t want it to change the surrounding html code
but just add the js file were it’s nesting in the html code

I an really new to javascript any help with this
Would be great

Thanks

Mac-10 : )

Vladdy
10-09-2003, 09:32 AM
myScript = document.createElement('script');
myScript.type = 'text/javascript';
myScript.src = 'Scripts/myScript.js';
document.getElementsByTagName('head')[0].appendChild(myScript);

mac-10
10-09-2003, 09:46 AM
thanks Vladdy

but I've got no Idea what that code does
or where I need to put could you explain
what the code does please

thanks

mac-10 : )

Vladdy
10-09-2003, 09:53 AM
// Create script element
myScript = document.createElement('script');
// Set the script element type attribute
myScript.type = 'text/javascript';
// Set the script element src attribute to the name of the file that contains your script. Do not forget relative path,
myScript.src = 'Scripts/myScript.js';
// Append script element to the document head element
document.getElementsByTagName('head')[0].appendChild(myScript);
// Compliant browsers will download and execute your code after the script node is appended to the document.head.

When you want to execute the script and what is the best way to incorporate it in the document depends on desired functionality.
Why do you need to have some script uploaded at the "runtime"?

mac-10
10-09-2003, 11:17 AM
I have been given a site to do
that uses java applets that gets
live data from a monitoring unit
there are a number of different
units. what needs to happen is
when the unit icon is click it
displays the js file which
holds the java applet and replace it
when the next unit is click

hope this make some sence

Vladdy
10-09-2003, 11:35 AM
It may make more sense if you had a link to the page you are working on...