473,505 Members | 13,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Image width & height lost in Firefox

My script is as follows:

function setImageSizes() {
var staticHeight = 70;

if(!document.getElementsByTagName || !document.images) return false;
var thumbnail = document.getElementsByTagName("img");

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;

//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.

I can't just use getAttribute on the image in the page as they have
been set incorrectly and this code can not be changed, therefore am
trying to get the dimension of the original image on the server.

Does anyone know what I can use instead?

Thanks

M

Aug 1 '06 #1
2 2573
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.

Aug 1 '06 #2
it never used
- doucment.images - and so the absence of that feature is not
significant here and should not be subject to testing here.
left in from previous tries, i tend to clean up the code once i've
found the solution. thanks tho.
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.
i wouldn't say it was perverse, i'd say it was an oversight. thanks
again.
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).
the images are on the server, not local disk - so i guess i'm lucky.
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.
so is there no other way of doing this? this is all I wanted to know
from this posting.
I can't just use getAttribute on the image in the page as they have
been set incorrectly
How, why?
if you really want the whole story.... the company i work for uses
external programmers to code the main stuff - this takes about 4 week
turn around. so i was hoping to get something together in a few days
that we can just add in. the images have been set as a fixed height and
width (70x80px) but the images are different sizes and so are out of
proportion in the main.
and this code can not be changed,
Why?
see above
Does anyone know what I can use instead?
Have the server insert the data directly into the javascript?
i don't know what this means, but doubt i can do it as i have no
control over server side code.

thanks for you advice.

M

Aug 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2128
by: Csaba Gabor | last post by:
Is there any way to determine the pixel height and width of an original image? Specifically, If I have <IMG id=myImg src="pic.jpg" height=200 width=300> can I figure out what the original size...
2
5347
by: AndrewW | last post by:
Hi I have an application that draws a selection rectangle over a map image. I can get it to work fine in IE and Opera, but not Firefox/Netscape. I've thrown the following small example...
0
1535
by: csgraham74 | last post by:
Hi there, i have creted a datagrid control to display images using the following code. <asp:DataGrid id="dg_Properties" runat="server" HorizontalAlign="Center" Width="450px"...
4
2736
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
7
27471
by: fredo | last post by:
I've studied Eric Meyer's pure css popups, version two: http://meyerweb.com/eric/css/edge/popups/demo2.html which pops up an image when I roll over a text link. Now I want to pop up a large...
2
13404
by: Atul | last post by:
I am unable to find image height and width in mozilla firefox. My code is working in IE but not in Mozilla. How can i find image width and height in mozilla? function check(sel) { if(sel != "")...
7
3626
by: petethebloke | last post by:
Can anyone help? I have a client who has made a "dynamic interactive map" of our city using Dreamweaver. Each map file has hotspots that pop-up a div with a little image when the mouse goes over...
1
2004
by: sravani1 | last post by:
This code runs like when i submit the form it takes the image and displayed and top of the image a map will displayed. But actually i want that when i give the image it checks the location in the map...
2
4079
by: studentofknowledge | last post by:
For some unknown reason ie is placing images I have in a div in a weird way. One image is overlapping another but this problem is not occuring in mozilla. I have looked at my code over and over again...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.