I develop Joomla websites/components/modules and plugins and every so often I require the ability to use JavaScript that triggers an event when the page is loaded. Most of the time this is done using the window.onload
function.
My question is:
- Is this the best way to trigger JavaScript events on the page loading or is there a better/newer way?
- If this is the only way to trigger an event on the page loading, what is the best way to make sure that multiple events can be run by different scripts?
The window.onload events are overridden on multiple creations. To append functions use the window.addEventListener(W3C standard) or the window.attachEvent(for IE). Use the following code which worked.