I have a script that starts when the page loads and I had been using this code below to start it:
if (window.addEventListener) {
window.addEventListener('load', otherRelatedParts, false);
}
else if (window.attachEvent) {
window.attachEvent('onload', otherRelatedParts );
}
but today I tried with a self invoking function like this:
(function() {
otherRelatedParts();
}())
It seems to work, in all browsers and is less code. Is this the preferred way to add events to the window load?