471,898 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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 2028
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

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.