JS Iframe loader

2019-02-19 07:14发布

问题:

I'm looking for a way to use jQuery/js to show a 'Loading...' message while an iframe is loading, when the iframe finished to load completely, the 'Loading...' text should disappear.

Is that possible with jquery/js?

Note: I do not have any control on the website within the iframe.

回答1:

<script>
function hide() {
  document.getElementById('loading').style.display='none';
}
</script>
<iframe onLoad="hide()" ... ></iframe>
<div id="loading">Please wait</div>

jquery:

$("iframe").load(function() { $("#loading").toggle()});