Solved

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

Posted on 2004-08-17
15
1,911 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now