Dynamic JavaScript Loading
While developing a custom jMaki widget we came across a problem in which we needed to load a javascript dynamically from another javascript file. There are atleast 2 ways I know this can be done. Here is one such method.
function jsinclude( jscriptfile )
{
// create a script node
var s = document.createElement('script');
s.src = jscriptfile;
s.type = "text/javascript";
// add it to the node called 'SOMEPARENT'.. it could be the HEAD node of the html page as below....
document.getElementsByTagName('head').item(0).appendChild(s);
}
Calling this function in your javascript you can load as many JS files as needed and embed them into your current DOM tree as follows :
jsinclude('dojofunctions.js');
Posted by insidemyhead [Sun] ( June 26, 2007 09:21 AM ) Permalink | Comments[4]

