10 examples of 'jquery getscript synchronous' in JavaScript

Every line of 'jquery getscript synchronous' 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
57export function loadjQueryDependentScript( url, callback ) {
58 debug( `Loading a jQuery dependent script from "${ url }"` );
59
60 if ( window.jQuery ) {
61 debug( `jQuery found on window, skipping jQuery script loading for "${ url }"` );
62 return loadScript( url, callback );
63 }
64
65 const loadPromise = loadScript( JQUERY_URL ).then( () => loadScript( url ) );
66
67 // if callback is provided, call it on resolution
68 if ( typeof callback === 'function' ) {
69 loadPromise.then(
70 () => callback( null ),
71 error => callback( error )
72 );
73 return;
74 }
75
76 // if not, return the Promise
77 return loadPromise;
78}
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

15function getScript(url, success) {
16 var script = document.createElement('script');
17 var head = document.getElementsByTagName('head')[0],
18 done = false;
19 script.src = url;
20 // Attach handlers for all browsers
21 script.onload = script.onreadystatechange = function() {
22 if (!done && (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete')) {
23 done = true;
24 // callback function provided as param
25 success();
26 script.onload = script.onreadystatechange = null;
27 head.removeChild(script);
28 };
29 };
30 head.appendChild(script);
31}
227function getScript(url, success) {
228
229 var script = document.createElement('script');
230 script.type = 'text/javascript';
231 script.async = true;
232 script.src = url;
233
234 var head = document.getElementsByTagName('script')[0],
235 done = false;
236
237 head.parentNode.insertBefore(script, head);
238
239 script.onload = script.onreadystatechange = function() {
240
241 if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
242
243 // Callback
244 success();
245 script.onload = script.onreadystatechange = null;
246 done = true;
247
248 };
249
250 };
251
252};
567function load(script, callback) {
568
569 if (script.state == LOADED) {
570 return callback && callback();
571 }
572
573 if (script.state == LOADING) {
574 return api.ready(script.name, callback);
575 }
576
577 if (script.state == PRELOADING) {
578 return script.onpreload.push(function() {
579 load(script, callback);
580 });
581 }
582
583 script.state = LOADING;
584
585 scriptTag(script.url, function() {
586
587 script.state = LOADED;
588
589 if (callback) { callback(); }
590
591 // handlers for this script
592 each(handlers[script.name], function(fn) {
593 one(fn);
594 });
595
596 // everything ready
597 if (allLoaded() && isDomReady) {
598 each(handlers.ALL, function(fn) {
599 one(fn);
600 });
601 }
602 });
603}
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}
25export default function replaceScript($script, callback) {
26 if (!$script.loaded) {
27 $script.loaded = true;
28 const s = document.createElement('script');
29 s.type = 'text/javascript';
30 [].forEach.call($script.attributes, attribute => {
31 // Set src later when everything else
32 // has been set.
33 if (attribute.name !== 'src') {
34 s.setAttribute(attribute.name, attribute.value);
35 }
36 });
37 if ($script.src) {
38 const cb = () => {
39 // Clean up onload and onerror handlers
40 // after they have been triggered to avoid
41 // these being called again.
42 try {
43 delete s.onload;
44 delete s.onerror;
45 } catch (e) {} // eslint-disable-line no-empty
46 callback();
47 };
48 s.onload = cb;
49 s.onerror = cb;
50 s.src = $script.src;
51 s.async = false;
52 } else {
53 s.innerHTML = $script.innerHTML;
54 }
55
56 const parentNode = $script.parentNode;
57
58 const typeAttr = $script.getAttribute('type');
59
60 // only run script tags without the type attribute
61 // or with a javascript mime attribute value
62 if (!typeAttr || runScriptTypes.indexOf(typeAttr) !== -1) {
63 // Remove the element so that we don't clutter the DOM
64 // with duplicates.
65 parentNode.removeChild($script);
66 // re-insert the script tag so it executes.
67 parentNode.appendChild(s);
68 }
69
70 // run the callback immediately for inline scripts
71 if (!$script.src) {
72 callback();
73 }
74 }
75}
2export default function loadScript(file, head, fn) {
3 if (typeof head === 'function') {
4 fn = head;
5 head = document.getElementsByTagName('head')[0];
6 }
7
8 let script = document.createElement('script');
9 let done = false;
10 let timer;
11
12 function ready(err) {
13 done = true;
14 script.onload = script.onerror = script.onreadystatechange = null;
15 clearTimeout(timer);
16 fn(err);
17 }
18
19 script.onload = script.onreadystatechange = function(e) {
20 if (!done && (!this.readyState || this.readyState == 'complete' || this.readyState == 'loaded')) {
21 ready(null);
22 }
23 };
24
25 script.onerror = function(error) {
26 if (!done) {
27 ready(error || new Error('Could not load file'));
28 }
29 };
30
31 timer = setTimeout(function() {
32 ready(new Error('Script loading timed-out'));
33 }, 3e4);
34
35 script.src = file;
36 head.appendChild(script);
37}
17function loadjQuery(url, callback) {
18 var script_tag = document.createElement('script');
19 script_tag.setAttribute("src", url)
20 script_tag.onload = callback; // Run callback once jQuery has loaded
21 script_tag.onreadystatechange = function () { // Same thing but for IE... bad for IE 10, it supports all
22 if (this.readyState == 'complete' || this.readyState == 'loaded') {callback();}
23 }
24 script_tag.onerror = function() {
25 loadjQuery("http://code.jquery.com/jquery-1.8.2.min.js", main);
26 }
27 document.getElementsByTagName("head")[0].appendChild(script_tag);
28}
32function LoadScriptDefer( url )
33 {
34 document.write( '<scr' + 'ipt type="text/javascript" src="../..//url" defer><\/scr' + 'ipt>' ) ;
35
36 }
82function loadScript(url, callback) {
83
84 var script = document.createElement("script")
85 script.type = "text/javascript";
86
87 if (script.readyState) { //IE
88 script.onreadystatechange = function () {
89 if (script.readyState == "loaded" || script.readyState == "complete") {
90 script.onreadystatechange = null;
91 callback();
92 }
93 };
94 } else { //Others
95 script.onload = function () {
96 callback();
97 };
98 }
99
100 script.src = url;
101 document.getElementsByTagName("head")[0].appendChild(script);
102 }

Related snippets