event.srcElement

J

Josselin

I am loading a group of items (urls of images to load) group.items

for each items I associate the filename and an <img> object on my page using :
....
var pair = new ImagePair(group.items);
....
function ImagePair( _file ) {
this.file = _file;
this.image = new Image();
this.image.width="0";
this.image.height="0";
document.body.appendChild(this.image);
}

then I want to check the image loading state of these images with a
loadImage_callback() function
....
(pair.image).onreadystatechange = loadImage_callback();
pair.image.src = group.items;
........
function loadImage_callback() {
// The loading state of some image has just updated
var obj = event.srcElement;
var group = _g_image_group;
// If the image has just loaded, update the count
if (obj.readyState == "complete")
group.numLoaded ++;
// Call imageupdate handler on group, if specified; otherwise call
imageupdate handler on document
if (group.imageupdate)
eval("group.imageupdate(group)");
else if (document.imageupdate)
eval("document.imageupdate(group)");

// If there are still images to load, schedule another callback
(condition isn't strictly
// necessary, since "complete" is the final stage of loading,
therefore when an image
// is "complete" it won't fire further readystatechange events)
if (group.numLoaded != group.numToLoad) {
obj.onreadystatechange = loadImage_callback();
}
}
........
upon run, I get a problem when I enter into the loadImage_callback() function :
my browser (Firefox) complains about the 'event.srcElement' , stating
that 'event' is not defined ...
what could be the trick ?
I am just a beginner using DOM, and progressing line by line ;-))

thansk for your help
 
R

Richard Cornford

Danny said:
Geckos/mozilla/ff/galeon do not use srcElement, only
IE and Opera,

And Konqueror, Safari, IceBrowser, Netfront, and otehrs.
geckos use .target

The W3C DOM events standard specifies a - target - property, so any DOM
standard browser can be expected to support it.
and you do need to pass the event as the
1st argument more or
less

function loadImage_callback(ev) {
// The loading state of some image has just updated
var obj = (window.external) ? event.srcElement : ev.target;

Any indirect inference about the object model in a browser is
ill-advised. The general principle of feature detection is that you make
the test as close to what you want to know as possible, preferably with
a one-to-one relationship, as such a test is least likely to be fooled
in unknown environments. In this case such a test is obviously
avalable:-

function loadImage_callback(ev) {
ev = ev||window.event;
var obj = (ev.srcElement)?ev.srcElement : ev.target;
...
}
Opera can do either, srcElement and .target :).

Opera does not implement - window.external -, and there is no reason to
believe that browsers that do will all also implement the IE event model
(either currently or in the future).

Richard.
 
R

Randy Webb

Richard Cornford said the following on 5/30/2006 3:13 AM:
Danny wrote:


Opera does not implement - window.external -, and there is no reason to
believe that browsers that do will all also implement the IE event model
(either currently or in the future).

And vice versa. The AOL browser implements about 98/99% of the IE event
model - including srcElement - but it does not implement window.external
so the garbage - oops, script - posted by Danny won't work for about 40
million users on the web.
 
J

Josselin

And Konqueror, Safari, IceBrowser, Netfront, and otehrs.


The W3C DOM events standard specifies a - target - property, so any DOM
standard browser can be expected to support it.


Any indirect inference about the object model in a browser is
ill-advised. The general principle of feature detection is that you make
the test as close to what you want to know as possible, preferably with
a one-to-one relationship, as such a test is least likely to be fooled
in unknown environments. In this case such a test is obviously
avalable:-

function loadImage_callback(ev) {
ev = ev||window.event;
var obj = (ev.srcElement)?ev.srcElement : ev.target;
...
}


Opera does not implement - window.external -, and there is no reason to
believe that browsers that do will all also implement the IE event model
(either currently or in the future).

Richard.

thanks to all for these valuable infos...
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top