Solved

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

Posted on 2004-08-17
15
1,923 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
[X]
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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

739 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