How to dynamically load external Javascript file _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces how to dynamically load external Javascript files. This article provides an example to illustrate how to use the js loader to dynamically load external Javascript files, interested friends can refer to a js loader that can dynamically load js files found on the Internet recently. The specific code is as follows:
JsLoader. js

Var MiniSite = new Object ();/*** judge the browser */MiniSite. browser = {ie:/msie /. test (window. navigator. userAgent. toLowerCase (), moz:/gecko /. test (window. navigator. userAgent. toLowerCase (), opera:/opera /. test (window. navigator. userAgent. toLowerCase (), safari:/safari /. test (window. navigator. userAgent. toLowerCase ()};/*** JsLoader object is used to load external js files */MiniSite. jsLoader = {/*** Load External js files * @ param sUrl the url of the js to be loaded * @ f Processing function */load: function (sUrl, fCallback) {var _ script = document. createElement ('script'); _ script. setAttribute ('charset', 'gbk'); _ script. setAttribute ('type', 'text/javascript '); _ script. setAttribute ('src', sUrl); document. getElementsByTagName ('head') [0]. appendChild (_ script); if (MiniSite. browser. ie) {_ script. onreadystatechange = function () {if (this. readyState = 'loaded' | this. readyStaate =' Complete') {// fCallback (); if (fCallback! = Undefined) {fCallback () ;}};} else if (MiniSite. browser. moz) {_ script. onload = function () {// fCallback (); if (fCallback! = Undefined) {fCallback () ;};} else {// fCallback (); if (fCallback! = Undefined) {fCallback ();}}}};

JsLoader. js Test

  
  

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.