For example you have following function:
function InitCustomCode()
{
// Your custom initialization
}
and you need to run it, when page loaded.
You can not just write:
<script>
InitCustomCode();
</script>
because it is going to crash Internet Explorer.So you need to add your function to window.onload event handler. However window.onload might be already taken by some other function and you don't have access to this defenition. Then you can use function below to add you handler and maintain already assigned function.
function addEvent(obj, evType, fn)
{
if (obj.addEventListener)
{
obj.addEventListener(evType, fn, false);
return true;
}
else
if (obj.attachEvent)
{
var r = obj.attachEvent("on" + evType, fn);
return r;
}
else
{
return false;
}
}