Dynamic reference of external Javascript script files, javascript scripts

Source: Internet
Author: User

Dynamically reference external Javascript script files [convert], javascript scripts

You can refer to the following method to dynamically reference external Javascript script files for webpages. The code is written in the Page_Init method.

VB. NET:



Is running, view the source code of HTML:



C #:


 


How to reference external javascript files in html

The above reference method is correct, but you do not know whether the file location is correct, otherwise there should be no problem.

If the JS and HTML files are in the same directory, use the <script type = text/javascript src = 1.js> </script> format.

How can I dynamically reference a JS file in Javascript?

Please consult me for details.

Online.

Var loadJs = function (url, callback ){
Var script = document. createElement ('script ');
Script. type = 'text/javascript ';
If (callback)
Script. onload = script. onreadystatechange = function (){
If (script. readyState & script. readyState! = 'Loaded' & script. readyState! = 'Complete') return;
Script. onreadystatechange = script. onload = null;
Callback ();
};
Script. src = url;
Document. getElementsByTagName ('head') [0]. appendChild (script );
}

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.