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 );
}