HTML onload Event Attribute


The HTML onload event attribute is triggered when an object has been loaded in an HTML document.

Syntax

Following is the syntax −

<tagname onload=”script”></tagname>

Let us see an example of HTML onload event Attribute−

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   body {
      color: #000;
      height: 100vh;
      background-color: #FBAB7E;
      background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);
      text-align: center;
      padding: 20px;
   }
</style>
<script>
   function get() {
      alert("Hi! you just refresh the document.");
   }
</script>
</head>
<body onload="get()">
<h1>HTML onload Event Attribute Demo</h1>
<p style="color:#db133a;">Now try to refresh this document.</p>
</body>
</html>

Output

Now try to reload the document to observe how onload event attribute works.

Updated on: 27-Sep-2019

162 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements