9.14. Controlling Image Loading: Waiting for Images and Checking Status

Even if you preload images, you often want to be sure that the images have finished loading before you perform certain tasks. For instance, because you cannot determine an image's width and height until the image has finished loading, programs that try to draw outlines around images must be careful how they go about it. As an example of a common but incorrect approach, consider Listings 9.17 and 9.18, which record the image's width and height in init, then draw a rectangle in paint based on these dimensions. Figure 9-10 shows the result in Internet Explorer 5 on a Windows 98 system; the rectangle is missing because the height is -1.

Figure 9-10. Trying to determine an image's ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.