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

Creating onload event within user-defined objects

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.