473,385 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

event.srcElement

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
4 11884


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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jeff Thies | last post by:
I have this IE specific bit of code for finding the originating node: var obj=window.event.srcElement; How do I do that cross browser (Opera, NS, Safari...)? Is there a standard DOM method? ...
1
by: john | last post by:
I1. notice that if you have an onclick event for both the document and for a particular element, the onclick for the element is called first and then it bubbles up to the one for the document. Is...
10
by: Noozer | last post by:
Is it possible to detect where on a page the click occurred when the OnClick event of the BODY tag is fired? Thx
6
by: Tom | last post by:
Hi, In the following code I have reproduced a problem in IE that is extremely annoying for my application. <html> <head> <script type="text/javascript">
26
by: johkar | last post by:
I need to cancel the link and execute a function onclick of all the links within the span tag which has a class of "container" assigned. There will be only one span tag with this class applied. ...
10
by: fusillo | last post by:
Hi, i've tried a test code about the Event Listener API but i've some problem about detaching the element firing the event with IE. Here's my code: <html> <head> <style type="text/css">...
5
by: jaysonnward | last post by:
Hello All: I've recently been recreating some 'dropdown menus' for a website I manage. I'm writing all my event handlers into my .js file. I've got the coding to work in Firefox, but the...
3
by: Larax | last post by:
I'm fighting with a strange problem that occures in IE, but let's start from beggining... I have a DIV element and SPAN element inside it, DIV has a onClick event attached while SPAN doesn't....
5
by: anEchteTrilingue | last post by:
Hi everybody. Thank you for reading my post. I am having trouble getting "this" to work in all versions of IE (it's fine in Firefox, opera, konqueror, etc). What I would like to do is add an...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.