Javascript DOM onload Event via HTML Tag onload function

Introduction

In JavaScript:

object.onload = function(){
       myScript};

This example uses the HTML DOM to assign an "onload" 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").onload = function() {myFunction()};

function myFunction() {//from   www.  ja v  a2  s.  com
  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