How to call a javascript function when iframe finished loading?

by cortez.connelly , in category: HTML & CSS , 19 days ago

How to call a javascript function when iframe finished loading?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by ryan.murray , 18 days ago

@cortez.connelly 

You can call a JavaScript function when an iframe has finished loading by adding an onload event listener to the iframe element. Here is an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<!DOCTYPE html>
<html>
<head>
  <title>Example</title>
  <script>
    function iframeLoaded() {
      // Code to execute when the iframe has finished loading
      alert('Iframe loaded!');
    }
  </script>
</head>
<body>
  <iframe src="https://www.example.com" onload="iframeLoaded()"></iframe>
</body>
</html>


In this example, the iframeLoaded() function will be called when the iframe has finished loading. You can replace the alert() function with any other code you want to run after the iframe has finished loading.