How do I call a JavaScript function on page load?

JavascriptWeb DevelopmentFront End Technology

To call a function on page load, use −

window.onload

Example

You can try to run the following code to implement a JavaScript function on page load

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <script>
         function alertFunction() {
            alert('ok');
         }
         window.onload = alertFunction;
      </script>
   </body>
</html>
raja
Published on 29-Jan-2018 15:23:41
Advertisements