Posted By

kajinka13 on 02/07/12


Tagged

javascript include loadfile


Versions (?)

Load in runtime di file js


 / Published in: JavaScript
 

Load in runtime di file js

  1. function loadjscssfile(filename, filetype) {
  2. if(filetype=="js"){ //if filename is a external JavaScript file
  3. var fileref=document.createElement('script')
  4. fileref.setAttribute("type","text/javascript")
  5. fileref.setAttribute("src", filename)
  6. } else if(filetype=="css"){ //if filename is an external CSS file
  7. var fileref=document.createElement("link")
  8. fileref.setAttribute("rel", "stylesheet")
  9. fileref.setAttribute("type", "text/css")
  10. fileref.setAttribute("href", filename)
  11. }
  12.  
  13. if(typeof fileref!="undefined")
  14. document.getElementsByTagName("head")[0].appendChild(fileref)
  15. }
  16.  
  17. loadjscssfile("http://code.jquery.com/jquery-1.6.min.js", "js") //dynamically load and add this .js file

Report this snippet  

You need to login to post a comment.