How to auto load javascript after iframe?

Member

by lily , in category: HTML & CSS , 12 days ago

How to auto load javascript after iframe?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by larissa , 11 days ago

@lily 

You can use the onload event of the iframe to trigger the loading of the JavaScript. Here is an example:

1
2
3
4
5
6
7
8
9
<iframe src="https://example.com" onload="loadScript()"></iframe>

<script>
function loadScript() {
  var script = document.createElement('script');
  script.src = 'path/to/your/script.js';
  document.body.appendChild(script);
}
</script>


In this example, the loadScript function is called when the iframe has finished loading. The function creates a new script element, sets its src attribute to the path of your JavaScript file, and appends it to the body element. This will load the JavaScript file after the iframe has finished loading.