The other way to achieve the same result is by using onload inside body tag of the page. You can read this article on how to keep the onload event handler to set the focus on input tag once the page loads.
Let us start some simple example of uses of window.onload function where we will prompt a message box once the page loads.
We can also achieve the same result by using onload event of body tag. Then what is the difference ?