Possible Duplicate:
How to include a JavaScript file in another JavaScript file?
I want to include a JavaScript file in a JavaScript file. include('filename.js');
is not working
What is the right code?
Possible Duplicate:
How to include a JavaScript file in another JavaScript file?
I want to include a JavaScript file in a JavaScript file. include('filename.js');
is not working
What is the right code?
function includeJS(incFile)
{
document.write('<script type="text/javascript" src="'+ incFile+ '"></script>');
}
Then include a second JavaScript file by calling:
includeJS('filename.js');
Use:
<script language="javascript" src="first.js"></script>
<script language="javascript" src="second.js"></script>
You can access the variables from the first file in the second file.
There isn't any need to include one JavaScript file into another. JavaScript code is globalised. You can include both the files in the HTML/JSP page.
Use document.write
in the first JavaScript function:
document.write('<scr'+'ipt type="text/javascript" src="filename.js" ></scr'+'ipt>');
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.