Viewing Images

A useful tool for designers is the ability to view all the images on a page, apart from the layout of the page. Script 17.7 allows you to peek behind the scenes of someone else’s page and see a list of the page’s individual images, the height and width of the images (in modern browsers), and their URLs.

To view images:

1.
var iWin,i,t='',di=document.images;
The bookmarklet starts and initializes four variables: iWin; i; t, which will later contain all the output; and di, which contains the document.images object.
2.
for (i=0;i<di.length;i++){
We now loop through each image in the document.
3.
if(t.indexOf(di[i].src)<0){
In this step, we check to see if we’ve already put the image on the page. This line of code keeps that from happening ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.