Best practice for using window.onload
Asked 07 September, 2021
Viewed 2.6K times
  • 60
Votes

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:

  1. Is this the best way to trigger JavaScript events on the page loading or is there a better/newer way?
  2. 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?

7 Answer