This javascript script resizes all image on the page, it can be controlled by the variable i and the greater than clause in the for loop. i=0 means it starts from the first image, change i=3 it will start from the forth image. The greater than clause will resize x amount of images. right now it resizes 10 images. The first 100 seen decides if the image is under 100 pixels wide not to resize it to 100, the second is what to resize the image too. comment any questions
<script language="javascript" type="text/javascript">
<!--
function resize_images()
{
for (i = 0; i < 10; i++)
{
while ( !document.images[i].complete )
{
break;
}
if ( document.images[i].width > 100 )
{
document.images[i].width = 100;
}
}
}
//-->
</script>
To implement the function on the page use this as your body tag
<body onLoad="resize_images()">
10 comments ↓
If you found this post useful click the share this button. Contribute below by adding a comment, no registration is required.
DCE Related Posts
Read Full Article...
This post teaches you how to replace CSS text links with an image and an image hover state. Read Full Article...
Read Full Article...
Nice simple script. Only iussue I have is an IE 7 script error which states:
Message: ‘document.images[...].complete’ is null or not an object
Any suggestions?
Do you have a link to where you are using it?
Thanks for the reply. I changed the amount of images to resize from 10 to 9 and it seemed to fix the issue. So Im thinking it may have been with the 2 digits. So instead of:
for (i = 0; i < 10; i++)
I used
for (i = 0; i < 9; i++)
and I didnt receive an IE7 error. Firefox works either way.
Hi, great tutorial; I can’t seem to get it running under IE7 either. Firefox worked like a charm, any ideas?
great script – it worked fine, but if i want to change one particluar image – what can i do?
Thank you,
Look for the code, the time
Teşekkürler designcodeexecute.com sayenizde tasarımlarıma renk katıyorum:)
@roberto bive the image an id the use getElementById
@ardeay could give an example how to do it? I’m interested too to change the script so it could work with selected images on web page, not all of theme.
Maybe the author could give a hand?
Nice simple script. Only iussue I have is an IE 7 script error which states:
Message: ‘document.images[...].complete’ is null or not an object
Any suggestions?
Leave a Comment