[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1955
  • Last Modified:

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

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
PCK1978
Asked:
PCK1978
  • 6
  • 3
  • 3
2 Solutions
 
ZvonkoSystems architectCommented:
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
 
PCK1978Author Commented:
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
 
PCK1978Author Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ZvonkoSystems architectCommented:
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
 
davidlars99Commented:
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
 
ZvonkoSystems architectCommented:
Hey! Greate site dave!
0
 
davidlars99Commented:
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
 
PCK1978Author Commented:
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
 
davidlars99Commented:
here's more about the image source control and animation..


cheers!
 dave
0
 
davidlars99Commented:
0
 
davidlars99Commented:
I don't think that anybody else could give better answers then us, so I'd say points must be splet!
0
 
davidlars99Commented:
what happened to this question..???!!!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now