onload event



The onload event occurs when an object has been loaded.

Usually, this is used within the <body> elements  to execute a script once a web page has completely loaded all content (including images, script files, CSS files, etc.).


Systnax

In HTML:

<element onload="myScript">

In JavaScript:

object.onload = function(){myScript};


In JavaScript, using the addEventListener() method:
object.addEventlistener("Load", myScript);



In JavaScript example:

<!DOCTYPE html>
<html>
<body>

<p>This example uses the HTML DOM to assign an "onload" event to an iframe element.</p>

<iframe id="myFrame" src="/default.asp"></iframe>

<p id="demo"></p>

<script>
document.getElementById("myFrame").onload = function() {myFunction()};

function myFunction() {
    document.getElementById("demo").innerHTML = "Iframe is loaded.";
}
</script>

</body>
</html>




https://www.w3schools.com/jsref/event_onload.asp

Comments

Popular Posts