| Author |
Get Image height and width
|
ramnna jain
Ranch Hand
Joined: Mar 16, 2009
Posts: 129
|
|
I want to get image size before I dynamically set it as background to a div object
so that, I can set height & width of the div accordingly.
I tried:
It worked fine with mozilla but not with IE.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56180
|
|
|
Please read this.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
ramnna jain
Ranch Hand
Joined: Mar 16, 2009
Posts: 129
|
|
In my html page I have one div tag with id 'somediv'.
On page load I want to set the div size, which is the size of the image.
To do this I created a new Image object & set the size of the div.
After setting the div size to the size of the image I set the image as background of the div object.
(Please see the above code.)
When I tried the code with Mozilla, the div get the size of the image.
But when I tried the same with Internet Explorer: The div is set to the size of the image.
But when I tried the same with different image sizes, in some cases the div did not take the size of the image.
This faulty behavior seldom happens, but I want it to completely resolve.
I am trying my code on Windows XP SP2, IE 6.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
I am guessing it has not loaded fully when you read the width and height. Try
Eric
|
 |
ramnna jain
Ranch Hand
Joined: Mar 16, 2009
Posts: 129
|
|
Thank you Eric... I am getting the desired results. Thank you again.
|
 |
ramnna jain
Ranch Hand
Joined: Mar 16, 2009
Posts: 129
|
|
The above mentioned problem was all because I named the jpg file 'bp.jpg'.
The problem is identified when tried with IE6.
When you name the file bp.jpg and try it with above mentioned code, and try to print
using . In IE6 it shows the wrong size.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
The name of the image has nothing to do with the width and height.
If you get a value that is different, are you sure it is not using a cached version of the file?
Eric
|
 |
ramnna jain
Ranch Hand
Joined: Mar 16, 2009
Posts: 129
|
|
In IE6 I cleared all the cache: Internet Options - General tab (Delete Cookies, Delete Files & Clear History).
I closed the Browser & restart it and tried the same. It is strange to see that when
I changed the names of different file to 'bp', and tried the results were same, erroneous.
I don't know what is the reason! But may be it is similar to try to create folder naming 'con',
which is a reserved word and we can't create one with this name.
|
 |
 |
|
|
subject: Get Image height and width
|
|
|