10 examples of 'javascript load url' in JavaScript

Every line of 'javascript load url' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
30function loadScript(url, callback){
31
32 var script = document.createElement("script");
33 script.type = "text/javascript";
34
35 if (script.readyState){ //IE
36 script.onreadystatechange = function(){
37 if (script.readyState == "loaded" ||
38 script.readyState == "complete"){
39 script.onreadystatechange = null;
40 callback();
41 }
42 };
43 } else { //Others
44 script.onload = function(){
45 callback();
46 };
47 }
48
49 script.src = url;
50 document.getElementsByTagName("head")[0].appendChild(script);
51}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

27function LoadScript( url )
28{
29 document.write( '<scr' + 'ipt type="text/javascript" src="/url"><\/scr' + 'ipt>' ) ;
30
31}
27function LoadScript( url )
28{
29 document.write( '<scr' + 'ipt type="text/javascript" src="..//url"><\/scr' + 'ipt>' ) ;
30
31}
27function LoadScript( url )
28{
29 document.write( '<scr' + 'ipt type="text/javascript" src="../..//url"><\/scr' + 'ipt>' ) ;
30
31}
1function loadScript(url, callback){
2 alert('url');
3 var script = document.createElement("script")
4 script.type = "text/javascript";
5
6 if (script.readyState){ //IE
7 script.onreadystatechange = function(){
8 if (script.readyState == "loaded" ||
9 script.readyState == "complete"){
10 script.onreadystatechange = null;
11 callback();
12 }
13 };
14 } else { //Others
15 script.onload = function(){
16 callback();
17 };
18 }
19
20 script.src = url;
21 document.getElementsByTagName("head")[0].appendChild(script);
22
23}
1function loadJS(url, isExternal)
2{
3 if( isExternal )
4 url = document.location.protocol == 'file:' ? 'http:' + url : url;
5 else
6 url += '?v=' + app.version + (!app.isProduction ? '&_=' + new Date().getTime() : '');
7
8 var ref = window.document.getElementsByTagName('script')[0];
9 var script = window.document.createElement('script');
10 script.src = url;
11 script.async = false;
12 ref.parentNode.insertBefore(script, ref);
13}
35function loadScript(url, callback)
36{
37 var script = document.createElement("script")
38 script.type = "text/javascript";
39
40 if (script.readyState)
41 { // IE
42 script.onreadystatechange = function()
43 {
44 if (script.readyState == "loaded" || script.readyState == "complete")
45 {
46 script.onreadystatechange = null;
47 callback();
48 }
49 };
50 } else
51 { // Others
52 script.onload = function()
53 {
54 callback();
55 };
56 }
57
58 script.src = url;
59 document.getElementsByTagName("head")[0].appendChild(script);
60}
42export function loadScript(url, callback) {
43 if (isNodeEnv()) {
44 return
45 }
46
47 var head = document.getElementsByTagName('head')[0];
48 var script = document.createElement('script');
49 script.type = 'text/javascript';
50 script.src = url;
51 //借鉴了jQuery的script跨域方法
52 script.onload = script.onreadystatechange = function(){
53 if((!this.readyState||this.readyState === 'loaded'||this.readyState === 'complete')){
54 callback && callback();
55 // Handle memory leak in IE
56 script.onload = script.onreadystatechange = null;
57 }
58 };
59 head.appendChild(script);
60}
4function loadScript(url, callback)
5{
6 // Adding the script tag to the head as suggested before
7 var head = document.getElementsByTagName('head')[0];
8 var script = document.createElement('script');
9 script.type = 'text/javascript';
10 script.src = url;
11
12 // Then bind the event to the callback function.
13 // There are several events for cross browser compatibility.
14 script.onreadystatechange = callback;
15 script.onload = callback;
16
17 // Fire the loading
18 head.appendChild(script);
19}
17function loadScript(url) {
18 var script = document.createElement('script');
19 script.src = url;
20 var firstScript = document.getElementsByTagName('script')[0];
21 firstScript.parentNode.insertBefore(script, firstScript);
22}

Related snippets