1
var frame_loaded = 0;

function setFrameLoaded() {
  frame_loaded = 1;
}

$('#btn').click(function() {
  if (frame_loaded == 1) {
    console.log('iframe loaded');
  } else {
    console.log('iframe not loaded');
  }
})

<button id="btn">click me</button>
<iframe onload="setFrameLoaded();" src='http://www.load41.com'/></iframe>

Hello, I need help. How can I detect if an iframe has finished loading in my website? I read that I could use onerror but I don't know how. Thanks!

Razer
  • 25
  • 3
  • What is the problem with the code above? The `setFrameLoaded` function doesn't get called? Or is it called too early? – aBnormaLz Aug 04 '20 at 08:01
  • Does this answer your question? [How can I detect whether an iframe is loaded?](https://stackoverflow.com/questions/12267010/how-can-i-detect-whether-an-iframe-is-loaded) – cloned Aug 04 '20 at 08:28
  • This always loads console.log('iframe loaded'); – Razer Aug 04 '20 at 16:26

0 Answers0