Javascript include – tricks

Posted by Script kiddie on Jul 11, 2012 in Programming |

You can include a javascript like this:

function include(filename)
 {
var head = document.getElementsByTagName('head')[0];
 script = document.createElement('script');
 script.src = filename; 
script.type = 'text/javascript';
 head.appendChild(script)

}
Read more here: http://forums.digitalpoint.com/showthread.php?t=146094

Or even better:
You can easily read another JS-file inside the javascript using jquery:

$.getScript("my_lovely_script.js", function(){
    alert("Script loaded and executed.");    
  // here you can use anything you defined in the loaded script 
});

Read here: http://stackoverflow.com/questions/950087/include-javascript-file-inside-javascript-file

Reply

Copyright © 2019 Web developer & geek blog All rights reserved. Theme by Laptop Geek.