em******@gmail.com wrote:
function setImageSizes() {
var staticHeight = 70;
if(!document.getElementsByTagName || !document.images) return false;
This is no rational. While the rest of the script does depend upon -
document.getElementByTagName -(though it doesn't need to) it never used
- doucment.images - and so the absence of that feature is not
significant here and should not be subject to testing here. On the
other hand the - document.createElement - is used (again
unnecessarily), but no effort has been made to verify its availability
in the environment (nor that the version available is a W3C DOM
standard version rather than the pre-DOM version of IE 4 and the dummy
version in late Opera 6 browser).
var thumbnail = document.getElementsByTagName("img");
As the - document.images - is already a collection of IMG elements in
the current document it is perverse to set about creating a new
nodeList that represents exactly the same collection.
for(var i=0; i<thumbnail.length; i++) {
if(thumbnail[i].className=="thumbnail_img") {
var tempImage = document.createElement("img");
tempImage.src = thumbnail[i].src;
//problem here
var theWidth = tempImage.width;
var theHeight = tempImage.height;
When a value is assigned to the - src - of an IMG element an
asynchronous request for a resource is made. If that resource does
supply dimension information for an image that information will not be
available until the response has arrived and has (at least) started to
be processed as an image. Attempting to read width and height
properties from the IMG element fractions of a millisecond after the
request is made will tend to be unsuccessful.
//scale new width
theWidth = Math.round((theWidth/theHeight)*staticHeight);
thumbnail[i].style.width=theWidth;
thumbnail[i].style.height=staticHeight;
}
}
}
window.onload=setImageSizes;
The problem is that Firefox (I'm using 1.5) shows tempImage width and
height as 0 - shows correctly in IE.
You can consider yourself extremely lucky if IE shows the correct
dimensions anywhere but sourcing the images from the local hard disk
(and not always then).
However, reading the widths and heights from IMG elements and Image
objects following the loading of an image file has never been
universally successful. There were always browsers that did not
transfer the information form the image to the properties.
I can't just use getAttribute on the image in the page as they have
been set incorrectly
How, why?
and this code can not be changed,
Why?
therefore am
trying to get the dimension of the original image on the server.
Does anyone know what I can use instead?
Have the server insert the data directly into the javascript?
Richard.