Jump to content

Javascript: Load remote js or css file dynamically


Recommended Posts

  • Administrators

Here is a neat little javascript function to load a remote CSS or Javascript file remotely:



function loadjscssfile(filename, filetype) {
if (filetype=="js") {
var fileref=document.createElement('script')
fileref.setAttribute("src", filename)
else if (filetype=="css") {
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
if (typeof fileref!="undefined") {

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now
  • Create New...