Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Javascript Window OnLoad Listener (See related posts)

This script gives the ability to run javascript functions after the page has loaded. I definitely can't take credit for this, as it's one I found, but I use it constantly.

   1  
   2  window.onloadListeners=new Array();
   3  
   4  window.addOnLoadListener = function (listener) {
   5  	window.onloadListeners[window.onloadListeners.length]=listener;
   6  }
   7  
   8  window.onload=function(){
   9  	for(var i=0;i<window.onloadListeners.length;i++){
  10  		func = window.onloadListeners[i];
  11  		func.call();
  12  	}
  13  }
  14  
  15  //window.addOnLoadListener(function);

You need to create an account or log in to post comments to this site.


Click here to browse all 5355 code snippets

Related Posts