10 examples of 'document loaded javascript' in JavaScript

Every line of 'document loaded javascript' 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
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}
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

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}
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}
75export function documentReady(cb) {
76
77 if (stateIsInteractive() || stateIsComplete()) {
78 cb();
79 }
80
81 function loadedHandler() {
82 removeHandler(doc, 'DOMContentLoaded', loadedHandler);
83 cb();
84 }
85
86 addHandler(doc, 'DOMContentLoaded', loadedHandler);
87}
21function scriptContentLoaded(scriptContent) {
22 jsParser({
23 input: scriptContent,
24 eventSource: eventSource,
25 eventPrefix: 'js:',
26 state: {
27 scriptUrl: event.src
28 }
29 }, jsTransformDone);
30
31 function jsTransformDone(error, newScriptContent) {
32 event.content = newScriptContent;
33 event.changed = newScriptContent !== scriptContent;
34 done(error, event);
35 }
36}
312private async _addJsScripts(): Promise<void> {
313 await Promise.all([
314 this._page.evaluateHandle(WendigoUtilsLoader),
315 this._page.evaluateHandle(SelectorQueryLoader),
316 this._page.evaluateHandle(SelectorFinderLoader)
317 ]);
318}
5export default function loadScript(url: string, callback: LoadScriptCallback) {
6 const script = document.createElement('script');
7 script.async = true;
8 script.src = url;
9 script.onerror = event => {
10 callback(false);
11 };
12 script.onload = () => {
13 callback(true);
14 };
15
16 // $FlowFixMe
17 document.head.appendChild(script);
18}
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}
166function iframeOnload() {
167 // 移除提交数据用的表单和iframe
168 if (div.parentNode) { div.parentNode.removeChild(div); }
169 // 释放全局回调函数
170 if (callbackName) { base.deleteGlobalVar(callbackName); }
171
172 onload('success');
173}
1function inject_script(script_name){
2 var s = document.createElement('script');
3 s.src = chrome.extension.getURL(script_name);
4 (document.head||document.documentElement).appendChild(s);
5 //s.onload = function() {
6 // s.parentNode.removeChild(s);
7 //};
8}

Related snippets