Starting a javascript code on page load

Hello again, I have been setting up a javascript marquee code to work in a widget I am trying to build for my site, and I almost have it except for on small problem I am having.

The marquee does not start scrolling on every page load, it is kinda hit or miss.

I found this code in the script which I beleive is suppose to start the marquee on page load but I don't think it is catching the user's updates and every page load in elgg.

           if (window.addEventListener)
           window.addEventListener("load", initializemarquee, false)
           else if (window.attachEvent)
           window.attachEvent("onload", initializemarquee)
           else if (document.getElementById)

Could someone point me in the right direction on choosing the best way to start this script?

Thanks a bunch