Search All Articles Submit your Website or Blog to A New Internet Library
Thursday, May 14, 2009
How to call multiple Javascript methods on window load using onload handler
We know that when we cannot assign mutilple functions to onload handler in javascript. It will just ovveride the previous function.
In order to set mutliple functions we need to consider Array and add all methods to that array.(functions can be added in Page or Usercontrol).
First Create onloadManager array.
if (!window.onloadManager)
{
window.onloadManager = new Array();
//add existing method to array
if (window.onload) {window.onloadManager[0] = window.onload;}
//Loop through array and execute each on onload
window.onload = function() {
for (index in window.onloadManager) { window.onloadManager[index](); }
};
}
Adding functions to onloadmanager array.
window.onloadManager[window.onloadManager.length] = function()
{
alert('function1 added');
};
Say in other user control on same page we add one more function.
window.onloadManager[window.onloadManager.length] = function()
{
alert('function2 added');
};
Subscribe to:
Post Comments (Atom)
Also Read other Top Articles
- JSON Serialization in VS 2008
- Implementing Forms Authentication in Silverlight Application.
- Making GridView Rows or Individual Cells Clickable and Selectable.
- Enabling browser back button for GridView Paging and Sorting in Ajax 1.1 and 3.5 (using Visual Studio 2005/ Visual studio 2008)
- How to pass values from User Control to Page or calling Page methods from User Control.
- What is WCF?
- New features in C# 4.0
- C# to VB.NET and VB.NET to C# online free converter tools.


1 comments:
nice article
Post a Comment
Post your comments/questions/feedback for this Article.