Detecting "image loaded successfully"

This is a discussion on "Detecting "image loaded successfully"" within the JavaScript Forum section. This forum, and the thread "Detecting "image loaded successfully" are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Dec 21st, 2006, 11:53
New Member
Join Date: Dec 2006
Location: The Netherlands
Age: 21
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Detecting "image loaded successfully"

I have a page with content.
Upon a certain action, two images get updated/replaced.
Because the images are on another server, it sometimes takes a couple of seconds.
* I would like to block specific actions (click on a button/other image) UNTIL the images are loaded.
* How do I detect when the images are done loading?
Something like readyState, complete, or something?
Any advice?

Thanks in advance.
Reply With Quote

  #2 (permalink)  
Old Dec 21st, 2006, 14:39
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Detecting "image loaded successfully"

You need to create a loop and check for

Code: Select all
// Declare the image
image = new Image;
image.src = "image.jpg";
// Use a loop with the following code in it
if (image.complete) {
    alert("The image is completely loaded");
}
Reply With Quote
  #3 (permalink)  
Old Dec 21st, 2006, 16:48
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,612
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: Detecting "image loaded successfully"

Back in my rule breaking days when standards were as important to me as an underwater hair drier, I used to use the 'onload' property on the image tag.

ie.:
<img src="/img.gif" onload="alert('Image loaded: '+this.src);"/>
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Reply With Quote
  #4 (permalink)  
Old Dec 21st, 2006, 23:18
Reputable Member
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to snow
Re: Detecting "image loaded successfully"

hehe, are you distancing yourself from that advice then spinal?
Reply With Quote
  #5 (permalink)  
Old Dec 22nd, 2006, 00:24
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Detecting "image loaded successfully"

Haha, I think I used that method first, but image.complete works if the image is cached as well. Onload will not work twice.
Reply With Quote
  #6 (permalink)  
Old Dec 22nd, 2006, 16:08
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,612
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: Detecting "image loaded successfully"

Quote:
Originally Posted by snow View Post
hehe, are you distancing yourself from that advice then spinal?
Damn right! LOL

I would use the technique Ryan showed above, and inorder to 'disable' the functionality, I'd add a div overlay to cover the entire screen.
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)

Last edited by spinal007; Dec 22nd, 2006 at 16:16.
Reply With Quote
Reply

Tags
javascript firefox

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 On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Show "Image" Depends On User "Status"? Monie Classic ASP 6 Oct 16th, 2007 01:22
"PHP Warning Module 'mysql' already loaded in Unknown on line 0" GLB PHP Forum 1 Sep 1st, 2007 22:57
? IS "meta name="robots" content="?" necessary in pages ? Love2Java Starting Out 6 Aug 8th, 2007 13:48
window.opener.document["nameForm"].getElementById("someid").value; doesnt work drpompeii JavaScript Forum 0 Feb 17th, 2007 23:09


All times are GMT. The time now is 10:35.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

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