10 examples of 'document onready' in JavaScript

Every line of 'document onready' 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
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}
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 documentReady(){
16 fadeInAnim();
17 socket = io.connect(location.protocol + '//' + document.domain +
18 ':' + location.port + appNamespace);
19
20 socket.on('connect', function() {
21 socket.emit('send_app_args');
22 });
23
24 socket.on('cli_args', function(cliArgs) {
25 args = cliArgs.args;
26 for (var i in args){
27 if (i != 'freq')
28 args[i] = args[i] || 0;
29 }
30 });
31}
3function onDocumentReady(callback) {
4 var state = document.readyState;
5 if (state === 'complete' || state === 'interactive') {
6 return callback();
7 }
8 document.addEventListener('DOMContentLoaded', function () {
9 callback();
10 });
11}
69function documentReady() {
70 // Get initial tracking status
71 matomoOptOutStatus();
72
73 // Add listener for the "do track" button.
74 var doTrackBtn = document.querySelector('.MatomoOptout-button--track');
75 doTrackBtn.addEventListener('click', function (event) {
76 event.preventDefault();
77 event.stopPropagation();
78
79 matomoOptOutTrack();
80 });
81
82 // Add listener for the "do not track" button.
83 var doBlockBtn = document.querySelector('.MatomoOptout-button--block');
84 doBlockBtn.addEventListener('click', function (event) {
85 event.preventDefault();
86 event.stopPropagation();
87
88 matomoOptOutStatus();
89 if (matomoOptOutIsTracked === true) {
90 matomoOptOutBlock();
91 }
92 });
93}
18function dom_ready(cb) {
19 function dom_ready_cb() {
20 dom_ready_cb = null_function;
21 cb();
22 }
23 document.addEventListener('DOMContentLoaded', dom_ready_cb, false);
24 var previous_onload = window.onload;
25 window.onload = function() {
26 dom_ready_cb();
27 previous_onload && previous_onload();
28 }
29}
42function domReady(callback) {
43 const doc = document;
44 const attach = 'addEventListener';
45
46 if (doc[attach]) {
47 doc[attach]('DOMContentLoaded', callback);
48 } else {
49 window.attachEvent('onload', callback);
50 }
51}
7function domReady(callback) {
8 if (doc.readyState === "complete" || (doc.readyState !== "loading" && !doc.documentElement.doScroll))
9 setTimeout(() => callback && callback(), 0)
10 else {
11 let handler = () => {
12 doc.removeEventListener("DOMContentLoaded", handler, false)
13 win.removeEventListener("load", handler, false)
14 callback && callback()
15 }
16 doc.addEventListener("DOMContentLoaded", handler, false)
17 win.addEventListener("load", handler, false)
18 }
19}
9export function domReady(callback) {
10 readyCallbacks.push(callback)
11}
68function isDocumentReady(iframe, callback) {
69 if (iframe.contentDocument.readyState === 'loading') {
70 iframe.contentDocument.addEventListener('DOMContentLoaded', function() {
71 callback();
72 });
73 } else {
74 callback();
75 }
76}
159function onReady(){
160
161 $(document).ready(function(){
162 // alert(1);
163 // alert($(window).width()); // 720
164 // alert($(window).height()); // 1230
165 // alert(0);
166 $('body').css('width',$(window).width() + 'px');
167 $('body').css('height',$(window).height() + 'px');
168 App.init();
169 });
170}

Related snippets