473,602 Members | 2,846 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.ge tElementsByTagN ame || !document.image s) return false;
var thumbnail = document.getEle mentsByTagName( "img");

for(var i=0; i<thumbnail.len gth; i++) {
if(thumbnail[i].className=="th umbnail_img") {
var tempImage = document.create Element("img");
tempImage.src = thumbnail[i].src;

//problem here
var theWidth = tempImage.width ;
var theHeight = tempImage.heigh t;

//scale new width
theWidth = Math.round((the Width/theHeight)*stat icHeight);

thumbnail[i].style.width=th eWidth;
thumbnail[i].style.height=s taticHeight;
}
}

}
window.onload=s etImageSizes;

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 2584
em******@gmail. com wrote:
function setImageSizes() {
var staticHeight = 70;

if(!document.ge tElementsByTagN ame || !document.image s) return false;
This is no rational. While the rest of the script does depend upon -
document.getEle mentByTagName -(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.create Element - 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.getEle mentsByTagName( "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.len gth; i++) {
if(thumbnail[i].className=="th umbnail_img") {
var tempImage = document.create Element("img");
tempImage.src = thumbnail[i].src;

//problem here
var theWidth = tempImage.width ;
var theHeight = tempImage.heigh t;
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((the Width/theHeight)*stat icHeight);

thumbnail[i].style.width=th eWidth;
thumbnail[i].style.height=s taticHeight;
}
}

}
window.onload=s etImageSizes;

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.getEle mentsByTagName( "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
2141
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 of pic.jpg is (had I not placed the height and width attributes on the image, whether in the original tag or later via javascript)?
2
5355
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 together to illustrate the problem - the problem being that FF/NE initially draw my rectangle before the icon changes immediately to the black no-entry icon. Then, when I let go of the mouse, the rectangle continues drawing, but it
0
1542
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" AutoGenerateColumns="False" ShowHeader="False"> <Columns><asp:BoundColumn Visible="False" DataField="Property_ID" HeaderText="Property_ID"></asp:BoundColumn><asp:TemplateColumn><ItemTemplate><table
4
2743
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. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is that I can't view the source???? The view source is disabled for this page. What causes this?
7
27481
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 image when I roll over a thumbnail. I've tried some things, but can't make it work. See here (Warning: adult matter):
2
13410
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 != "") { document.getElementById('newImg').src = sel; document.getElementById('newImgDiv').style.visibility = "visible"; } }
7
3639
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 them. They also link to another file. I've converting the application to a PHP-AJAX system at http://www.ilex-urc-maps.com/testing.html but I can't get the dynamically altered hotspots to work. Any ideas? Please don't tell me that the client...
1
2014
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 and after displayed it.plz tell that how to start the logic. <?php // Connect to database $errmsg = "";if (! @mysql_connect("localhost","root","sreeni")) { $errmsg = "Cannot connect to database"; } @mysql_select_db("my_db1");...
2
4087
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 but cant seem to find out what the problem is. I think this could be fixed with a i.e hack??? please advise the problem of the overlapping image is occuring in imagerow2 div on line 56. please see my code below here is my html <!DOCTYPE...
0
7993
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8268
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6730
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5440
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3900
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2418
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1254
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.