Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run more than one javascript function on page load

Tags:

javascript

  1. I want run some javascript functions on page load, which ways are exist and which one is better ?
  2. can i call more than one function in <body onclick="my function();"> ?
like image 241
biglibigli Avatar asked Dec 11 '25 18:12

biglibigli


2 Answers

First, you do not want to force the user to click on the page in order for the functions to execute.

The most basic way to do is:

<body onload="yourFunction();">

Then, in a <script> tag in the <head> have your function call all your other functions:

function yourFunction(){
    function1();
    function2();
    // some other code not in a function...
    //...
}
like image 95
Jeremy Avatar answered Dec 14 '25 21:12

Jeremy


<body onload="yourFunction1();yourFunction2();">
like image 20
George Cummins Avatar answered Dec 14 '25 20:12

George Cummins