How to call a javascript function when iframe finished loading?

by cortez.connelly , in category: HTML & CSS , 6 months ago

How to call a javascript function when iframe finished loading?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by ryan.murray , 6 months 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.

Related Threads:

How to call a javascript function from within iframe?
How to call a javascript function in a mustache template?
How to know if the iframe has completed loading with javascript?
How to call laravel route from javascript function?
How to invoke a function in iframe using javascript?
How to call javascript when specific page is loaded into an iframe?