For external communication JS
var loadJs = function(jsPath) { var s = document.createElement('script'); s.setAttribute('type', 'text/javascript'); s.setAttribute('src', jsPath); document.getElementsByTagName('head')[0].appendChild(s); }; loadJs('http://other.com/other.js');
For the same JS domain link (using jQuery)
var getScript = function(jsPath, callback) { $.ajax({ dataType:'script', async:false, cache:true, url:jsPath, success:function(response) { if (callback && typeof callback == 'function') callback(); } }); }; getScript('js/other.js', function() { functionFromOther(); });
molokoloco
source share