By looking at the output of console.log(document)
, I find document
has these properties:onload=null;onloadstart=null;onloadend=null;onreadystatechange=null;
I write the following code:
<html>
<head><title>test</title></head>
<body>
<script>
document.onload=function(){alert("document.onload");};
document.onloadstart=function(){alert("document.onloadstart");};
document.onloadend=function(){alert("document.onloadend");};
document.onreadystatechange=function(){alert("document.onreadystatechange");};
</script>
<div>hello</div>
</body>
</html>
Interestingly, document.onload,document.onloadstart,document.onloadend
are never called, while document.onreadystatechange
is called twice, why?