I need to make an alert after all content is loaded and user can see all images 100%.
I do this way – I made a function in the end of my webpage (be fore the BODY tag is closed:
JavaScript
x
4
1
window.onload=function(){
2
alert("This is my alert text");
3
}
4
But it doesnot work. The alert comes when some images are not loaded. Especially on mobile devices. On desktop it works sometimes
Advertisement
Answer
This will help:
JavaScript
1
7
1
document.addEventListener('readystatechange', function(event) {
2
console.log(event.target.readyState); // check for more states
3
if (event.target.readyState === "complete") {
4
alert("Everything loaded now including images, scripts and styles.");
5
}
6
});
7
Please check @ CodePen https://codepen.io/animatedcreativity/pen/07c67507a741a76f4ae208d52a29cf7b/
^ I have added big images for you in the example. Alert will show up only after everything is fully loaded.