By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,161 Members | 1,698 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,161 IT Pros & Developers. It's quick & easy.

event.srcElement

P: n/a
I am loading a group of items (urls of images to load) group.items[i]

for each items I associate the filename and an <img> object on my page using :
....
var pair = new ImagePair(group.items[i]);
....
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[i];
........
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


May 29 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a


Geckos/mozilla/ff/galeon do not use srcElement, only IE and Opera, geckos
use .target 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;
Opera can do either, srcElement and .target :).

Danny

May 30 '06 #2

P: n/a
Danny wrote:
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.
May 30 '06 #3

P: n/a
Richard Cornford said the following on 5/30/2006 3:13 AM:
Danny wrote:
<snip>
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).


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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 30 '06 #4

P: n/a
On 2006-05-30 09:13:50 +0200, "Richard Cornford"
<Ri*****@litotes.demon.co.uk> said:
Danny wrote:
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.


thanks to all for these valuable infos...

May 30 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.