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

Member

by shyann , in category: Javascript , 7 months ago

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

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by tressie.damore , 7 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.

Related Threads:

How to auto load javascript after iframe?
How to add iframe with javascript to ajax loaded content?
How to test content of iframe using jest?
How to rotate an iframe using javascript?
How to invoke a function in iframe using javascript?
How to pass credentials to iframe using javascript?