Reputation: 479
I am working on a project where I upload files using an 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.
Can anybody help me with this?
Upvotes: 1
Views: 2600
Reputation: 479
I found solution:
this is parent document of 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:
<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 :)))
Upvotes: 2
Reputation: 545
You can try following jquery code:
$(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);
});
Upvotes: 0