<html> <head> <script type="text/javascript"> function changeSize(strTemp) {alert(strTemp);} </script> </head> <body> <script type='text/javascript'> document.body.onload = function(){changeSize('added');}; </script> </body> </html> This addition of eventHandler dynamically works in IE but not in mozilla. How to do it for mozilla In the above code 'added' is displayed in alert box on page load in IE, how to make it happen in mozilla.
Use 'window.onload' instead of 'document.body.onload'. But changing 'window.onload' that way also removes all previously assigned window.onload event handlers... You may want to use a dedicated framework like jQuery, Prototype or YUI, which nicely allow adding event handlers dynamically.