Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i fire an event when document readyState is complete

Tags:

javascript

I want to fire and event when the DOM has completely loaded. I checked out document.readyState but it's not an event. I want to fire it when the readyState is complete. How do I do that?

like image 273
ptamzz Avatar asked Dec 01 '22 02:12

ptamzz


2 Answers

Some easy googling point me to this code:

// alternative to DOMContentLoaded
document.onreadystatechange = function () {
    if (document.readyState == "complete") {
        initApplication();
    }
}

And to this link

like image 139
Naftali Avatar answered Dec 03 '22 15:12

Naftali


Handle the window.load event.

This will only fire when all external resources (including images) have loaded.

like image 23
SLaks Avatar answered Dec 03 '22 15:12

SLaks