How to wait for iframe content to load using only javascript?

Member

by shyann , in category: Javascript , 2 months ago

How to wait for iframe content to load using only javascript?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by tressie.damore , 2 months ago

@shyann 

You can wait for an iframe content to load using Javascript by adding an event listener for the 'load' event on the iframe element. Here is an example:

1
2
3
4
5
6
7
8
// Get the iframe element
var iframe = document.getElementById('myIframe');

// Add an event listener for the 'load' event
iframe.addEventListener('load', function() {
  // iframe content has loaded, you can now access and manipulate its contents
  console.log('Iframe content has loaded');
});


This code will wait for the iframe content to load and then execute the callback function once the content has finished loading.