window.onload in javascript code example
Example 1: window.onload
window.onload = function() {
// Some code
};
Example 2: window onload javascript
//Use window.onload to to execute JavaScript only after the HTML has loaded
//Syntax:
window.onload = function() {
//JavaScript goes here
}
Example 3: js document onload
//use
window.onload=()=>{};
Example 4: window.onload
window.onload = function() {
init();
doSomethingElse();
};
Example 5: window onload
function load(argument) {
// body...
}
window.onload = load;
Example 6: load js
const log = document.querySelector('.event-log-contents');
const reload = document.querySelector('#reload');
reload.addEventListener('click', () => {
log.textContent ='';
window.setTimeout(() => {
window.location.reload(true);
}, 200);
});
window.addEventListener('load', (event) => {
log.textContent = log.textContent + 'load\n';
});
document.addEventListener('readystatechange', (event) => {
log.textContent = log.textContent + `readystate: ${document.readyState}\n`;
});
document.addEventListener('DOMContentLoaded', (event) => {
log.textContent = log.textContent + `DOMContentLoaded\n`;
});