
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between window.onload and document.onload in Javascript?
document.onload
It gets fired prior to loading of images and other external content. document.onload event is fired before the window.onload.
window.onload
It gets fired when the complete page loads, which includes images, scripts, css, etc.
Example
Here’a an example to understand onload.
<html> <head> <title>JavaScript Animation</title> <script> <!-- var imgObj = null; function init() { imgObj = document.getElementById('myImage'); imgObj.style.position= 'relative'; imgObj.style.left = '0px'; } function moveRight() { imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px'; } window.onload =init; //--> </script> </head> <body> <form> <img id="myImage" src="/images/html.gif" /> <p>Click button below to move the image to right</p> <input type="button" value="Click Me" onclick="moveRight();" /> </form> </body> </html>
- Related Questions & Answers
- What is the difference between == and === in JavaScript?
- What is the difference between jQuery and JavaScript?
- What is the difference between JavaScript and C++?
- What is the difference between Java and JavaScript?
- What is the difference between JavaScript and ECMAScript?
- What is the difference between comments /*...*/ and /**...*/ in JavaScript?
- What is the difference between Bower and npm in JavaScript?
- What is the difference between call and apply in JavaScript?
- What is the difference between null and undefined in JavaScript?
- What is the difference between a++ and ++a in JavaScript?
- What is the difference between getter and setter in JavaScript?
- What is the difference between substr() and substring() in JavaScript?
- What is the difference between setTimeout() and setInterval() in JavaScript?
- What is the difference between functions and methods in JavaScript?
- What is the difference between Map and WeakMap in JavaScript?
Advertisements