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.

2

1 Answer 1

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>

Not the answer you're looking for? Browse other questions tagged or ask your own question.