Javascript DOM onload Event via addEventListener() method

Introduction

In JavaScript, using the addEventListener() method:

object.addEventListener("load",
       myScript);

This example uses the addEventListener() method to attach a "load" event to an iframe element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<iframe id="myFrame" src="https://www.java2s.com"></iframe>
<p id="demo"></p>
<script>
document.getElementById("myFrame").addEventListener("load", myFunction);

function myFunction() {/*  w  ww .j  a  v  a2  s .  c o m*/
  document.getElementById("demo").innerHTML = "Iframe is loaded.";
}
</script>

</body>
</html>
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