Reputation: 1
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.
Upvotes: 0
Views: 1722
Reputation: 166
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>
Upvotes: 2