JavaScript显示在iframe加载时加载gif [英] JavaScript Show loading gif while Iframe loads

查看:110
本文介绍了JavaScript显示在iframe加载时加载gif的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要加载GIF才能在iframe加载时显示。

这就是我想出的结果:

I need a loading GIF to show up while the iframe is loading.
This is what I came up with:

<div id="m-load" style="position:relative;top:45%;left:45%;">
<img src="images/loader.gif"/></div>
<iframe src="http://myserver.com/myfile.html" id="m-iframe"></iframe>

在我输入的iframe源文件中:(myfile.html)

And in the iframe source file I entered:(myfile.html)

<head>
<script>
top.document.getElementById('m-load').style.display ="none";
</script>
</head>

但这在Firefox中不起作用(权限被拒绝)。

Any实现这一目标的其他方式?

But this won't work in Firefox (permission denied).
Any other way of achieving this?

推荐答案

您需要使用<$在相同页面上执行此操作c $ c> onload 在所有iframe加载后触发的事件如下:

You need to do it on the same page using onload event which fires after all iframes are loaded like this:

// show loading image

window.onload = function(){
  // hide loading image
}







<img id="img" src="images/loader.gif"/></div>

<script>
window.onload = function(){
   document.getElementById('img').style.display = "none";
}
</script>

这篇关于JavaScript显示在iframe加载时加载gif的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆