简体   繁体   English

在加载iframe之前显示loading.gif

[英]Displaying loading.gif before iframe is loaded

So I have this button that when clicked on will send you to the next slide (void(0)). 因此,我有这个按钮,单击该按钮会将您带到下一张幻灯片(void(0))。 The next slide is an iframe which is loaded only when you click on the button. 下一张幻灯片是iframe ,仅当您单击按钮时才加载。 Before the iframe is fully loaded, an animated GIF should show up and in turn hide after the content is fully loaded. iframe完全加载之前,应显示动画GIF,然后在内容完全加载后隐藏。

In my case, the GIF is never displayed. 就我而言,永远不会显示GIF。 It's totally blank until the iframe is fully loaded. iframe完全加载之前,它完全空白。 What is wrong? 怎么了?

Here is the script: 这是脚本:

<script type="text/javascript"> 
    function hideLoading() { 
        document.getElementById('loading').style.display = "none"; 
        document.getElementById('edtwo').style.display = "block"; 
    } 
</script> 

The button: 按钮:

<span id="nextBtn1"><a href="javascript:void(0);"
onClick='document.getElementById("edtwo").src="ed2.html";'></a></span>

And the next slide which includes the GIF and the iframe: 下一张幻灯片包括GIF和iframe:

<li><div id="loading"><img src="_img/loading.gif" alt="Loading"/></div>
<iframe id="edtwo" onload="hideLoading()";></iframe></li>

The problem is that your iframe is initially displayed (and moreover, added in the DOM tree). 问题是您的iframe最初会显示(此外,还会添加到DOM树中)。 Inspite of its empty src attribute it will load empty page and execute onload event handler. 尽管其src属性为空,但它将加载空白页并执行onload事件处理程序。 So you will have your indicator hidden as a result of calling hideLoading. 因此,由于调用hideLoading,您的指标将被隐藏。

As you can see in this exmaple, onload triggers without clicking on link. 如您在示例中所见,加载触发器无需单击链接即可触发。

You can remove frame from DOM tree and add it when user clicks "Next" button or change .style.display to empty string (to show it) of gif loader at this time. 您可以从DOM树中删除框架,并在用户单击“下一步”按钮时添加它,或者此时将.style.display更改为gif加载器的空字符串(以显示它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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