Load in runtime di file js


/ Published in: JavaScript
Save to your folder(s)

Load in runtime di file js


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.