10 examples of 'javascript document.onload' in JavaScript

Every line of 'javascript document.onload' 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
166function iframeOnload() {
167 // 移除提交数据用的表单和iframe
168 if (div.parentNode) { div.parentNode.removeChild(div); }
169 // 释放全局回调函数
170 if (callbackName) { base.deleteGlobalVar(callbackName); }
171
172 onload('success');
173}
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

8export function loadScript (src, callback) {
9 var scriptElement = document.createElement('script')
10 scriptElement.src = src
11 scriptElement.defer = true
12 callback && scriptElement.addEventListener('load', callback)
13 document.body.appendChild(scriptElement)
14}
23function _onLoad () {
24 if (!this.content) {
25 this.content = window.JSON && window.JSON.parse ? JSON.parse(this.xmlhttp.responseText.toString()) : eval(this.xmlhttp.responseText.toString())
26 }
27 _super._onLoad.call(this)
28}
43target.addEventListener('load', function onload () {
44 resolve(blob);
45}, {once: true} as any); // hack
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}
44function onload() {
45 var x = document.getElementsByTagName('a');
46 for (var i=0; i<x.length; i++) {
47 if (x[i].getAttribute('type') == 'popup') {
48 x[i].onclick = function () {
49 return popup(this.href)
50 }
51 }
52 }
53 var y = document.getElementsByTagName('A');
54 for (var i=0; i<y.length; i++) {
55 if (y[i].getAttribute('type') == 'popup') {
56 y[i].onclick = function () {
57 return popup(this.href)
58 }
59 }
60 }
61}
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}
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}
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}

Related snippets