Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App
Next Article:
HTML DOM onload Event
Next article icon

HTML DOM onload Event

Last Updated : 26 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The HTML DOM onload event in HTML occurs when an object has been loaded. The onload event is mostly used within the <body> tag, in order to run the script on the web page that will load all the content completely. The onload event can be used to check the user's browser type and browser version and load the version of the web page based on the information. The onload event can also be used for cookies. 

In HTML:

<element onload="scriptFile">
HTML
<!DOCTYPE html> <html> <body>  <img src="https://media.geeksforgeeks.org/wp-content/uploads/20211113003851/geeks-300x83.png"        id="imgid"        alt="GFG_logo"       onload="document.getElementById('pid').innerHTML = 'Image loaded';">  <p id="pid"></p> </body> </html> 

Using the addEventListener() method:

object.addEventListener("load", scriptFile);
HTML
<!DOCTYPE html> <html> <body>     <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20211113003851/geeks-300x83.png"           id="imgid" alt="GFG_logo">     <p id="pid"></p>      <script>         document.getElementById("imgid")         .addEventListener("load", GFGFun);         function GFGFun() {             document.getElementById("pid")             .innerHTML = "Image loaded";         }     </script> </body> </html> 

In JavaScript:

object.onload = function(){scriptFile};
HTML
<!DOCTYPE html> <html> <body>     <img src="https://media.geeksforgeeks.org/wp-content/uploads/20211113003851/geeks-300x83.png"           id="imgid" alt="GFG_logo">     <p id="pid"></p>     <script>         // Set the onload event for the image         document.getElementById("imgid").onload = function () {             document.getElementById("pid").innerHTML = "Image loaded";         };     </script> </body> </html> 

Supported tags:

  • <body>: It is used to define the main content present inside an HTML page.
  • <frame>: It is used to divide the web browser window into multiple sections where each section can be loaded separately.
  • <iframe>: It is used to define a rectangular region within the document in which the browser can display a separate document, including scrollbars and borders.
  • <img>: It is used to add images inside a webpage/website.
  • <input type="image">: It is used to specify the type of <input> element to display.
  • <link>: It is used to define a link between a document and an external resource.
  • <script>: It is used to define the client-side script.
  • <style>: It is used to modify our text, viewed in the page.

Next Article
HTML DOM onload Event

V

Vijay Sirra
Improve
Article Tags :
  • Web Technologies
  • HTML
  • Web technologies
  • HTML-DOM

Similar Reads

    HTML | DOM onunload Event
    The onunload event in HTML occurs once the page is unloaded. for example, when the page is loading and the browser window has been closed by the user or submit a form, click on a link, etc. This event also occurs when the page is reloaded. Supported Tags <body> Syntax:   In HTML:  <element
    1 min read
    HTML DOM onplay Event
    The DOM onplay event occurs when the audio/video is played. The audio/video can be played either by the user or programmatically. Supported Tags <audio> <video> Syntax: In HTML:<element onplay="myScript">In JavaScript: object.onplay = function(){myScript};In JavaScript, using the a
    1 min read
    HTML DOM onloadstart Event
    The HTML DOM onloadstart event occurs when the loading process of a specified audio/video starts. events that occur during the loading process of an audio/video: onloadstartondurationchangeonloadedmetadataonloadeddataonprogressoncanplayoncanplaythrough Syntax: In HTML:<element onloadstart="myScri
    1 min read
    HTML DOM onloadeddata Event
    The DOM onloadeddata event in HTML occurs when the current frame data is loaded but the next frame's data is not enough data to play the audio/video. Events that occur during the loading process of an audio/video: onloadstartondurationchangeonloadedmetadataonloadeddataonprogressoncanplayoncanplaythr
    1 min read
    HTML | DOM onshow Event
    The onshow event occurs when a user right click on en element and <menu> element is shown as a context menu. Supported Tags <menu> Syntax: In HTML: <element onshow="Script">In JavaScript: object.onshow = function(){Script};In JavaScript, using the addEventListener() method: object.
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences