简体   繁体   中英

Loading gif not waiting for iFrame to load?

I want a loading .gif to display until everything has loaded including an embedded iframe . However, currently the loading gif disappears once everything has loaded apart from the iframe . How can I get it to wait until the iframe has loaded too?

Currently using this:

<script>
  $(window).ready(function() {
    $('#loadinga').hide();
  });
</script>

Thanks

<iframe name="xyz"></iframe>

<script>
  var expectedLoadCount = 2; 

  function checkEverythingLoaded() {
    expectedLoadCount--;
    if (expectedLoadCount > 0) return
    $('#loadinga').hide();
  }

  $("#xyz").on("load", checkEverythingLoaded);
  $(window).ready(checkEverythingLoaded);
</script>

suppose your iframe id is iframeId

then try with this-

<iframe id="iframeId" src="..."></iframe>

<script>
document.getElementById('iframeId').onload = function() {
$('#loadinga').hide();

  alert('iframe is loaded');
};
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM