I am experimenting with the write and onload method. Here is my code:
<!DOCTYPE html>
<html>
<head>
</head>
<body onload="document.write('body loaded!')">
<h1>Hello World!</h1>
<img onload="document.write('img loadeld!')" src="smiley.gif" alt="Smiley face" width="42" height="42" />
</body>
</html>
If I run this in a browser, it displays “img loadeld” and just “freezes”, it seems to load the page endlessly. I expected the browser to output "img loadeld", and then when the body element is ready, "body is loaded" and just stops, as usual.
My questions:
- Why such a hang? Why is the onload event on the img element blocking the browser from continuing and rendering "body loaded"?
- Why, if I remove the onload handler from the img element, the response will be as expected - "body loaded" and the page is not locked.
source
share