HTML onload Event Attribute

HTMLDOMWeb DevelopmentFront End Technology

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.

raja
Published on 27-Sep-2019 14:53:19
Advertisements