Good day ! I'm learning javascript and have a problem with the timers. I just wanted to check if the onload event is triggered once the whole page is written including the text modified via javascipt. For that purpose I wanted to slow down the writing of the text by inducing a 200 ms delay between characters.
The test I use is the following:
<!DOCTYPE html>    
<head>
<meta charset="utf-8">
<title>Onload test</title> 
<script>
    function load() {
        alert("The page is considered loaded !");
    }
    function writeSlowly(text, timer) {
        var L= text.length;
        var st = "";
        function write (seq) {
            document.getElementById("st").innerHTML = seq;
        };
        for (var i = 0; i < L; i += 1) {
            st += text[i];
            setTimeout(write(st), timer);
        };
    };
</script>
</head>
<body>
<p id="st"></p>
<script>
    writeSlowly("This pages takes a while to load", 200);
    window.onload = load;
</script>
</body>
</html>
The page loads as if there were no delay at all. Actually I expected the text (32 characters long) to take about 32 x 200 ms =~ 7 seconds. When debugging (with Firebug - I use Firefox 30) the program steps through the lines but the timer has no effect. The page displays almost instantaneously.
 
     
     
    
This page ... until it is complete. So I think to be correct in saying: "the page is considered loaded when the static elements are read and the code for the dynamic elements are read but not necessarily fully executed."
– RAH Jul 08 '14 at 22:23