How to know if the iframe has completed loading with javascript?

by cali_green , in category: Javascript , a month ago

How to know if the iframe has completed loading with javascript?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by samara , a month ago

@cali_green 

You can use the load event listener in JavaScript to know when an iframe has completed loading. Here is an example code snippet to achieve this:

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

iframe.addEventListener('load', function() {
  console.log('Iframe has completed loading');
});


In this code, replace 'myIframe' with the id of your iframe element. The load event is fired when the iframe and all its contents have finished loading. You can also perform any actions you need to do after the iframe has completed loading within the event listener.