Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Javascript Image objects not loaded

Reply
Thread Tools

Javascript Image objects not loaded

 
 
guywmustang
Guest
Posts: n/a
 
      09-02-2006
So, basically this is the problem.

I have this...
<div id="mainframe">
<img src="image.jpg" id="image">
</div>

Then when I try to in a function say...

function checkImage()
{
var image = document.getElementById("image");
var height = image.height;
}

--------------
Many times the image height will not be defined.

I recently changed the past so it uses AJAX to change the <img src...
stuff to return new data for that inner HTML block..

Still the image will not have properties.
Now, this is a problem in IE/FF, but not in opera.

Any ideas on how to make sure the image is loaded so its height/width
properties are available... either by swapping the image.src or by
using ajax to swap out the div innerHTML??

 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      09-02-2006
guywmustang said the following on 9/2/2006 3:06 AM:
> So, basically this is the problem.
>
> I have this...
> <div id="mainframe">
> <img src="image.jpg" id="image">
> </div>
>
> Then when I try to in a function say...
>
> function checkImage()
> {
> var image = document.getElementById("image");
> var height = image.height;
> }
>
> --------------
> Many times the image height will not be defined.


It will be defined, it just won't be defined when you try to call it.

> I recently changed the past so it uses AJAX to change the <img src...
> stuff to return new data for that inner HTML block..
> Still the image will not have properties.
> Now, this is a problem in IE/FF, but not in opera.
>
> Any ideas on how to make sure the image is loaded so its height/width
> properties are available... either by swapping the image.src or by
> using ajax to swap out the div innerHTML??


Use the onload of the img to make sure it is loaded.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
 
 
 
guywmustang
Guest
Posts: n/a
 
      09-04-2006
The onload is exactly what I needed! Thanks!

I don't know all the javascript events and such, so this is a good
forum to turn to thanks to the people here!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
How to find that, image is loaded or not balakrishnan.dinesh@gmail.com Javascript 2 09-22-2006 10:13 AM
Image is not loaded sometimes balakrishnan.dinesh@gmail.com Javascript 0 09-04-2006 08:57 AM
java -verbose doesn't show "loaded from" for classes loaded from custom jars in the classpath Udo Corban Java 0 01-23-2004 09:32 AM
Re: how to programatically give assembly loaded from network the same trust as those loaded from local host? Marcelo Birnbach [MS] ASP .Net 0 06-27-2003 11:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57