Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-08-17
15
Medium Priority
?
1,949 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
12 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 400 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 400 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

783 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