JS dynamic loading CSS and javascrpt files

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax css tutorial document download dynamic loading file file download files

JS Dynamic loading CSS Tutorials and javascrpt files
This article is a free JS dynamic loading css and javascrpt file download package, if you are looking for dynamic loading JS or dynamic load CSS JS function here is very good ha, He can traverse javascrt or link to add again depending on user settings.
*/

Function $import (path,type,title) {
  var s,i
  if (type = "JS") {
    var ss = document.getElementsByTagName ("script");
    for (i =0;i < ss.length i++)
    {
      if ( SS[I].SRC && ss[i].src.indexof (path)!=-1) return ss[i];
   }
    s      = document.createelement ("script");
    s.type = "text/web Effects";
    s.src  =path;
 }
  Else if (type = = "css")
  {
    var ls = document.getelementsbytagname ("link");
    for (i = 0; i < ls.length i++)
    {
      if (ls[i) . href && ls[i].href.indexof (path)!=-1) return ls[i];
   }
    s          = document.createelement ("link");br>     s.rel      = "Alternate stylesheet";
    s.type     = "Text/css";
    s.href     = path;
    s.title    = title;
    s.disabled = false;
 }
  else return;
  var head = document.getElementsByTagName ("head") [0];
  Head.appendchild (s);
  return s;
}

//Call Method
$import (' aa.js ', ' js ', ' JavaScript ');
</script>
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.