Javascript DOM onload Event

Introduction

Execute a JavaScript immediately after a page has been loaded:

View in separate window

<!DOCTYPE html>
<html>
<body onload="myFunction()">

<h1>Hello World!</h1>

<p id="demo"></p>
<script>
function myFunction() {/* w ww  .jav a  2s  .c  o m*/
  document.getElementById("demo").innerHTML = "Page is loaded";
}
</script>

</body>
</html>

The onload event occurs when an object has been loaded.

Bubbles:
Cancelable:
Event type:
Supported HTML tags:







No
No
UiEvent if generated from a user interface, Event otherwise.
<body>,
<frame>,
<iframe>,
<img>,
<input type="image">,
<link>,
<script>,
<style>



PreviousNext

Related