How to check iframe is loaded in javascript?

by aniya.jaskolski , in category: HTML & CSS , 6 days ago

How to check iframe is loaded in javascript?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by aubrey , 5 days ago

@aniya.jaskolski 

You can check if an iframe is loaded in JavaScript by using the load event listener on the iframe element. Here's an example:

1
2
3
4
5
var iframe = document.getElementById('myIframe');

iframe.onload = function() {
  console.log('iframe is loaded!');
};


In this example, we are adding an onload event listener to the iframe element with the ID myIframe. When the iframe is fully loaded, the console will display "iframe is loaded!". This is a simple way to check if an iframe is loaded in JavaScript.