IE shows false and Firefox shows true

G

Gianni

I get different results with the following script
in IE and Firefox.

tes.gif does not exist so it should show false
on both browsers.

IE shows false and Firefox shows true.
Am I misunderstanding something?


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<script type="text/javascript">
function alertComplete()
{
var msg = document.getElementById("testid").complete;
alert(msg);
}
</script>

</head>

<body onload="alertComplete()">
<img id="testid" src="tes.gif" alt="test gif" />
</body>
</html>
 
T

Thomas 'PointedEars' Lahn

Gianni said:
I get different results with the following script
in IE and Firefox.

tes.gif does not exist so it should show false
on both browsers.

IE shows false and Firefox shows true.
Am I misunderstanding something?

Yes. Neither is the `onload' event an indication that all images in the
document have been loaded, nor is `complete' an interoperable (standard)
property.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

XHTML or HTML?
<script type="text/javascript">
function alertComplete()
{
var msg = document.getElementById("testid").complete;
alert(msg);
}
</script>

</head>

<body onload="alertComplete()">
<img id="testid" src="tes.gif" alt="test gif" />
</body>
</html>


PointedEars
 
G

Gianni

Thomas said:
Yes. Neither is the `onload' event an indication that all images in the
document have been loaded, nor is `complete' an interoperable (standard)
property.


XHTML or HTML?

Thanks for responding.

You seem to imply that this is no way to ensure that
a document has finished loading? Is there a way of
doing this?

You ask XHTML or HTML? I thought what I had specified,
in the script, was XHTML, but you seem to imply from
your question that the script is ambiguous? How can
I change it for the better?
 
T

Thomas 'PointedEars' Lahn

Gianni said:
Thanks for responding.

You seem to imply that this is no way to ensure that
a document has finished loading?

There is no way to ensure that when the `load' event occurs (sorry for using
the wrong name before) the document *and* all its referred content (e.g
images) have been (down)loaded (and displayed).
Is there a way of doing this?

Probably yes, but the approach that is arguably the most reliable is not a
standards-compliant one (and so certainly none that results in Valid HTML or
XHTML). Your `img' elements need a proprietary `onload' attribute, and you
can hope for that in the code called there, if it is called, a counting
property that is initialized with zero is increased by one each time. You
can then, after each increase, determine if the current property value
equals the number of `img' elements in the document. If that were the case,
you could assume that all images have been loaded.

The alternative to that is that you do the same but let the code called be
assigned by dynamically adding an event listener for the `load' event (which
is however, again, not specified in a public standard to apply to IMG/img
element nodes) using standards-compliant or proprietary methods. The risk
involved is that an image completes loading before you can add the listener,
but that might be mitigated by using said proprietary `complete' property of
each element object.
You ask XHTML or HTML? I thought what I had specified,
in the script, was XHTML, but you seem to imply from
your question that the script is ambiguous?

The markup is.
How can I change it for the better?

Declare and use HTML 4.01. What do you need XHTML for here?


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top