Saturday, November 27, 2010

How to add multiple functions to the windows.onload method in JavaScript

  How to add multiple functions to the windows.onload method.
  var DeveloperCaster = {
            OnLoad: function (_function) {
                var _current = window.onload;
                if (typeof window.onload != 'function') {
                    window.onload = _function;
                } else {
                    window.onload = function () {
                        if (_current) {
                            _current();
                        }
                        _function();
                    };
                }
            }
        };


How to use it:
<script language="JavaScript">
   DeveloperCaster.OnLoad(function () {
            alert('Function 1');
        });

        DeveloperCaster.OnLoad(function () {
            alert('Function 2');
        });
</script>

No comments:

Post a Comment