10 examples of 'ondocumentready' in JavaScript

Every line of 'ondocumentready' 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
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}
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

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}
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}
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}
139export function documentReady() {
140 return new Promise((resolve, reject) => {
141 if (
142 document.readyState === 'interactive' ||
143 document.readyState === 'complete'
144 )
145 resolve()
146 else document.addEventListener('DOMContentLoaded', resolve)
147 })
148}
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}
113function isDocumentReady() {
114 // https://mdn.io/Document/readyState
115 return / MSIE \d/.test(navigator.userAgent) ?
116 document.readyState === 'complete'
117 :
118 document.readyState !== 'loading'
119}
81private static onDocumentReady(callback: Function) {
82 jQuery(document).ready(callback);
83}
116function onDocumentAvailable()
117{
118 if (this._document)
119 func(callbackWrapper);
120 else {
121 if (callbackWrapper)
122 callbackWrapper("No document");
123 }
124}
185function mainDocumentAvailable(document)
186{
187 this._rootDOMNode = document;
188
189 dispatchCallbacks.call(this);
190}

Related snippets