Forum Moderators: open
Is there a way to use that to limit the size of the image that's displayed? I want to display the image at full size up to a point, say width="100". For any pic bigger than that, I want to display it at width="100".
My script prints out the HTML using this variable (I've added in your suggestion, as I understand it):
imagehtml='<img src="'+image[0]+'" width="'+image[0].width+'" alt="">
Below is my script. What is the easiest way to get images under 100px wide to display at full size, and anything over 100px to display at 100px?
------
<script language="JavaScript" type="text/javascript">
<!--
//Specify image paths and optional link (set link to "" for no link):
var dynimages=new Array()
dynimages[0]=["/image00.jpg", ""]
dynimages[1]=["/image01.jpg", ""]
dynimages[2]=["/image02.jpg", ""]
dynimages[3]=["/image03.jpg", ""]
function returnimgcode(theimg){
var imghtml=""
if (theimg[1]!="")
imghtml='<a href="'+theimg[1]+'">'
imghtml+='<img src="'+theimg[0]+'">'
if (theimg[1]!="")
imghtml+='</a>'
return imghtml
}
function modifyimage(loadarea, imgindex){
if (document.getElementById){
var imgobj=document.getElementById(loadarea)
if (imgobj.filters && window.createPopup){
imgobj.style.filter=filterstring
imgobj.filters[0].Apply()
}
imgobj.innerHTML=returnimgcode(dynimages[imgindex])
if (imgobj.filters && window.createPopup)
imgobj.filters[0].Play()
return false
}
}
//-->
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset:utf-8">
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
//Specify image paths and optional link (set link to "" for no link):
var dynimages=new Array()
dynimages[0]=["./image00.jpg", ""]
dynimages[1]=["./image01.jpg", ""]
function returnimgcode(theimg)
{
var imghtml=""
if (theimg[1]!="")
imghtml='<a href="'+theimg[1]+'">'
var img = new Image();
img.src = theimg[0];
imghtml+='<img src="'+theimg[0]+'" width="'+img.width+'" height="'+img.height+'">'
if (theimg[1]!="")
imghtml+='</a>'
return imghtml
}
//-->
</script>
</head>
<body>
<div id="container">
<script type="text/javascript">
for( var i = 0; i < dynimages.length; i++ )
{
alert( returnimgcode(dynimages[i]) );
}
</script>
</div>
</body>
</html>