469,588 Members | 2,741 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,588 developers. It's quick & easy.

Creating onload event within user-defined objects

Hello,

I would like to create an onload event within my object.
The following works fine :

function TEST()
{
this.image= new Image();
}
TEST.prototype.Initialize = function()
{
var _this = this;
this.image.onload = function(){_this.Alerting("Image Loaded");};
this.image.src = "winxp.gif";

}
TEST.prototype.Alerting = function(i_string){alert(i_string);}

var mTest = new TEST();
mTest.Initialize();
mTest.image.attachEvent("onload",function(){alert( "Load event access from
page");},false);

But i would rather be able to use :

mTest.attachEvent("onload",function(){alert("Load event access from
page");},false);

and therefore create an event listener within my object rather than use the
image.onload event listener.

Thank you for your time.


Mar 13 '07 #1
1 1956
On Tue, 13 Mar 2007 19:47:45 +0100, webgour <ol***********@hotmail.com
wrote:
Hello,

I would like to create an onload event within my object.
The following works fine :

function TEST()
{
this.image= new Image();
}
TEST.prototype.Initialize = function()
{
var _this = this;
this.image.onload = function(){_this.Alerting("Image Loaded");};
this.image.src = "winxp.gif";

}
TEST.prototype.Alerting = function(i_string){alert(i_string);}

var mTest = new TEST();
mTest.Initialize();
mTest.image.attachEvent("onload",function(){alert( "Load event access from
page");},false);

But i would rather be able to use :

mTest.attachEvent("onload",function(){alert("Load event access from
page");},false);

and therefore create an event listener within my object rather than use
the
image.onload event listener.

Thank you for your time.

attachEvent() is a Microsoft proprietary function. It will work, but you
will be limiting yourself to Microsoft's attempt at a web browser only.

The standard method is addEventListener(), but since the programmers of
the world's most used browser decided to implement their own proprietary
method, you won't have much use of the standard.

In these cases, falling back on the 'old' methods are best. So please,
continue to assign to image.onload. It might look less elegant, but it
beats the browser incompatilities.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Mar 16 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Da Costa Gomez | last post: by
12 posts views Thread by vadivasbro | last post: by
5 posts views Thread by Andy Fish | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.