1

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?

4

2 回答 2

2

我找到了解决方案:

这是 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>

这是 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>

享受伙计们:)))

于 2013-08-08T22:01:04.910 回答
0

您可以尝试以下 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);
});
于 2013-07-27T22:53:27.353 回答