473,406 Members | 2,620 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,406 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 2094
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Da Costa Gomez | last post by:
Hi all, I've been eluded the last couple of *days* on the onload mystery within the frame and function context. Problem is as follows: - frameset with two frames. One called scripts and the...
12
by: vadivasbro | last post by:
Very simple code. Why won't this work? <html> <head> <script type="text/javascript"> window.onload = document.getElementById("thisThing").style.background = "red"; </script>
2
by: foldface | last post by:
Hi I am aware of how Page_Load and OnLoad work. What I am curious about is -why- there are 2 mechanisms for doing the same thing, in particular why Visual Studio will generate code to implement...
8
by: Stephen Adam | last post by:
Hi there, I am developing a web site with a number of pages, I want each page to have the same heading section which will include both the raw html and vb.net code which handle rollovers for...
1
by: CES | last post by:
All, I was wondering if someone could point me to a tutorial on creating & accessing functions from within a wrapper function. I've created a group of functions related to a timer event. All...
5
by: Andy Fish | last post by:
Hi, I have an asp.net web application which uses a pop-up form that works a bit like a dialog box. when the user clicks "OK" it does a postback (basically a form post if you don't know .net) to...
3
by: ajfish | last post by:
Hi, I have a web form with smart navigation turned on. the html has an onload event which calls a javascript function and the contents of this function are dynamically generated on the server...
6
by: Daz | last post by:
Hello everyone, I would like to open a child window from the parent, and add an onload event listener to the child window which will tell the parent when the document has loaded. As far as I...
8
by: dd | last post by:
Has anyone found a way around the problem IE has if you create elements (script or div, doesn't seem to matter) BEFORE the document.readyState is "complete" ? I know you can sometimes get away...
4
by: Jason | last post by:
Hi, Here's the scenario: I have a web application that has window A and window B. A user has both window A and B open - window A is in the foreground and window B is behind it. If the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.