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. Here is the script
We can also achieve the same result by using onload event of body tag. Then what is the difference ?
Difference between window.onload function and body tag onload. We can't keep any code to access the property set or any other related objects of the elements present in body of the page by using window.onload function. Say we want to select the text present inside a text box as soon as the page loads. This is not possible by using window.onload event but this is possible by using body onload command. The code below will generate error message.
Number of User Comments : 2