How to wait the loading of an iframe?

by scotty_walker , in category: HTML & CSS , 3 months ago

How to wait the loading of an iframe?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by tressie.damore , 3 months ago

@scotty_walker 

You can wait for the loading of an iframe using JavaScript by setting an event listener for the "load" event on the iframe element. Here's an example:

1
2
3
4
5
6
7
8
// Get a reference to the iframe element
const iframe = document.querySelector('iframe');

// Add a "load" event listener to the iframe
iframe.addEventListener('load', function() {
    // Your code to execute after the iframe has finished loading
    console.log('Iframe has finished loading');
});


This code will wait for the iframe to finish loading before executing the code inside the event listener. You can then perform any actions you need to once the iframe has finished loading.