Answer the question
In order to leave comments, you need to log in
How to track full page load?
The initial task is simple: programmatically open the page at the specified URL and do something after that, for example, output information to the console that everything has successfully loaded. But for some absolutely incomprehensible reasons for me, onload is not triggered on some sites, although the site seems to have all the permissions. The code turned out like this:
function loadPage(url) {
return new Promise((res, rej) => {
let my_lovely_window;
try {
my_lovely_window = window.open(url)
} catch (e) {
rej(e);
}
my_lovely_window.addEventListener('load', res, true);
my_lovely_window.addEventListener('error', rej, true);
});
}
loadPage('/')
.then(e => console.log(`page "${ decodeURIComponent(e.target.location.href) }" loaded successfully`))
.catch(e => console.log(`error occurred: `, e))
function loadPage(url) {
return new Promise((res, rej) => {
let my_lovely_window;
console.log(`starting procedure with url "${ url }"`);
try {
console.log(' creating window...')
my_lovely_window = window.open(url)
console.log(' window created!')
} catch (e) {
console.log('error!')
rej(e);
}
console.log(' setting listeners...')
my_lovely_window.addEventListener('load', res, true);
my_lovely_window.addEventListener('error', rej, true);
console.log(' listeners are set!');
});
}
loadPage('/')
.then(e => console.log(`page "${ decodeURIComponent(e.target.location.href) }" loaded successfully`))
.catch(e => console.log(`error occurred: `, e))
Answer the question
In order to leave comments, you need to log in
I'm using this
window.onload = function () {//тело функции}
//или
document.addEventListener("DOMContentLoaded", function() {
//func
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question