0

How I run a script tag when the page load using javascript.I need a on page load script execute code.i searched a lot of website for that code but i am not getting any relevant code.

Yora
  • 1
  • https://stackoverflow.com/questions/4523954/page-lifecycle-in-javascript – Siavoshkc Oct 29 '22 at 07:44
  • Does this answer your question? [How to make JavaScript execute after page load?](https://stackoverflow.com/questions/807878/how-to-make-javascript-execute-after-page-load) – Anna Gevel Nov 02 '22 at 07:42

1 Answers1

2

You can use onload event :
html binded to the body for example:

<body onload="myFunction()">

or in javascript using addEventListener:

document.body.addEventListener("load", myFunc);

or

Try this:

<script>
   window.onload = function myFunc() {

       //do stuff

   }
</script>
Annak942
  • 146
  • 8