iFrame onload JavaScript event

iFrame onload JavaScript event

Use the iFrames .onload function of JavaScript:

<iframe id=my_iframe src=http://www.test.tld/>
    <script type=text/javascript>
        document.getElementById(my_iframe).onload = function() {
    <!--OTHER STUFF-->

document.querySelector(iframe).addEventListener( load, function(e) {

    this.style.backgroundColor = red;


} );
<iframe src=example.com ></iframe>

iFrame onload JavaScript event

Your code is correct. Just test to ensure it is being called

function doIt(){
  alert(here i am!);

<iframe onload=doIt()></iframe>

Leave a Reply

Your email address will not be published.