Creating onload event within user-defined objects

W

webgour

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.
 
O

OmegaJunior

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.
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top