Possible Duplicate:
Include javascript file inside javascript file?
Hello,
I want to include a javascript file in a javascript file.
include('filename.js');
is not working
What is the right code.
Thanks Jean
Possible Duplicate:
Include javascript file inside javascript file?
Hello,
I want to include a javascript file in a javascript file.
include('filename.js');
is not working
What is the right code.
Thanks Jean
function includeJS(incFile)
{
document.write('<script type="text/javascript" src="'
+ incFile+ '"></scr' + 'ipt>');
}
</script>
Then include a second JavaScript file by calling:
includeJS('filename.js');
use document.write in first javscript function..
document.write('<scr'+'ipt type="text/javascript" src="filename.js" ></scr'+'ipt>');
<script language="javascript" src="first.js"></script>
<script language="javascript" src="second.js"></script>
You can access the variables from first in second
There is no need to include one js file into another. Javascripts are globalised one. You can include both the files in the HTML/JSP page.
This should help you
http://stackoverflow.com/questions/950087/include-javascript-file-inside-javascript-file
If you do the document.write method bear in mind that the code within the file will not be guaranteed to be loaded once document.write returns.
You may want to have some type of callback mechanism when the included file has loaded. That is, register a callback before document.write, and at the very end of your javascript file make a call to the callback function.