[英]How do I detect when an iframe starts loading and when it finishes loading
I am working on a project where I upload files using an iframe
. 我正在使用iframe
上传文件的项目中。
I need to show a pre-loader when the iframe
starts uploading the file and hide the pre-loader when the iframe
finishes loading. 我需要在iframe
开始上传文件时显示预加载器,并在iframe
完成加载后隐藏预加载器。
Can anybody help me with this? 有人可以帮我吗?
I found solution: 我找到了解决方案:
this is parent document of Iframe: 这是iframe的父文档:
<div id="loader"></div>
<div class="iframeClass">
<iframe src="myIframe.php" id="myIframe" frameborder="0"></iframe>
</div>
<script type="text/javascript">
document.getElementById('myIframe').onload = function() {
document.getElementById('loader').style.display = 'none';
}
</script>
this is iframe document: 这是iframe文件:
<form action="myIframe.php" method="post" enctype="multipart/form-data" id="myForm">
<input type="file" name="myFile" id="myFile" />
</form>
<script type="text/javascript">
document.getElementById('myFile').onchange = function() {
top.document.getElementById('loader').style.display = 'block';
document.getElementById('myForm').submit();
}
</script>
enjoy guys :))) 享受大家:)))
You can try following jquery code: 您可以尝试以下jquery代码:
$(document).ready(function(){
alert("Iframe Start Loading ...");
var ifr=$('<iframe></iframe>', {
id:'frame',
src:'http://ernagroup.com',
style:'display:none',
load:function(){
$(this).show();
alert('iframe loaded !');
}
});
$('body').append(ifr);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.