Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

What to use instead of Image.complete in mozilla firefox?

Posted on 2004-08-17
15
1,916 Views
Last Modified: 2012-05-05
HI
I have a problem, I use an image to determine if another event has occured.
The event is when a PDF file has been created in the same directory as the image.

In my javascript I simply poll if the image is complete every 100 ms.
When the image exists I create a link to the document.

This works great in IE but Mozilla don't like the
if (document.getElementById(ImageName).complete == false)
Mozilla gives me this error.
Error: document.getElementById(ImageName) has no properties
Source File: Test.html
Line: 8

Anyone know a property like .complete that works in Mozilla?

Here is the code. If you want to test it just create an image named error.gif then then
the link should link correct.

<SCRIPT>
  function ValidateImage(ImageName, LinkName)
  {
    if (document.getElementById(ImageName).complete == false)
    {
      setTimeout("UpdateImage(document.DocumentImage)", 100);
      document.getElementById(LinkName).innerHTML="Please wait while document is being generated...";
    };
  }

  function UpdateImage(ImageObj)
  {
    ImageObj.src = ImageObj.src;
    if (ImageObj.complete == true)
    {
      document.getElementById('DocumentLink').innerHTML="Click here to proceed to the document";
      document.getElementById('DocumentLink').href="http://www.in-process.se";
    };
  }

  function Void()
  {
    ;
  }
</SCRIPT>

<FORM>
  <A HREF="javascript:Void()" id="DocumentLink" >test</A>
  <IMG NAME="DocumentImage" SRC="error.gif" ALIGN="left" BORDER="0" onLoad="ValidateImage('DocumentImage', 'DocumentLink')" onError="ValidateImage('DocumentImage', 'DocumentLink')" WIDTH="0" HEIGHT="0">
</FORM>

/Kristoffer
0
Comment
Question by:PCK1978
  • 6
  • 3
  • 3
15 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 100 total points
ID: 11819583
Use for the image also an ID.
Or access the image by image collection.
Like this:
 if (document.images[ImageName].complete == false)


In either way I do not know wether Netscape provides the complete property. I do not think so.
Anyway, I would solve it by assigning again and again the image source and react to onLoad and onError.

0
 

Author Comment

by:PCK1978
ID: 11819777
hmm
can you explain the last thing again.
Or do you mean:
If onError is triggered I wait and then try to load the image again.
finally the onLoad will be triggered and then my pics is "complete"
0
 

Author Comment

by:PCK1978
ID: 11820156
Ok I tried to rewrite the code.
Here I use the onLoad and onError.
This code works perfect in IE but bugs alot in Mozilla :(
In Mozilla it detects that the image exists when it doesn't. Every second refresh :)

<HTML>
<TITLE></TITLE>
<SCRIPT>

ValidatorOnLoad = function()
{
  alert("Image exists");
}

ValidatorOnError = function()
{
  setTimeout("ReloadImage()", 100);
  alert("Image reloading");
}

function ReloadImage()
{
  var ValidatorImage = new Image;

  ValidatorImage.onload = ValidatorOnLoad;
  ValidatorImage.onerror = ValidatorOnError;
  ValidatorImage.src = "error.gif";

  alert("Image reloaded");
}

ReloadImage();

</SCRIPT>
<BODY>
</BODY>
</HTML>
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 63

Expert Comment

by:Zvonko
ID: 11820897
You assumption was exactly what I wanted to propose. But your code is absolutely strange! Where is the image?
If you make it local in a function by prefixing the reference by "var" the is that reference freed after function ends.

0
 
LVL 13

Assisted Solution

by:davidlars99
davidlars99 earned 100 total points
ID: 11821798
hi, image[i].complete that's the way which will work an all major browsers,
a little while ago I used it on my website to make progress bar and seems to that it's working perfectly
www.frozendev.com

cheers!
 dave
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11822152
Hey! Greate site dave!
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 11837865
thanks...
hey PCK1978 why don't you try

var img=new Array();
img[0]=new Image();
img[0].src="url to you image"

that should work...
0
 

Author Comment

by:PCK1978
ID: 11838233
I'll try that later today, but the .complete problem is solved now :)
I upgraded from Mozilla 0.9.2 -> 0.9.3 and that solved it.
Only problem now is then a picture is missing mozilla just wait forever for something.
atleast when I try to load an image with an <IMG> tag.
I'll try loading the pics with Javascript and see if Mozilla stops when the image is missing.
(the image will always be missing the first seconds, depending on how fast the blueprint can be generated)

Kristoffer
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 11857588
here's more about the image source control and animation..


cheers!
 dave
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 11925542
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 12380193
I don't think that anybody else could give better answers then us, so I'd say points must be splet!
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13700894
what happened to this question..???!!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Grunt script for Build Process 1 42
Writing comments on <p></P> or paragraph 2 19
Load data upon clicking a button 8 34
Running a javascript project in WebStorm 2 24
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question