【问题标题】:How could I check if an iframe have completely loaded a PDF file如何检查 iframe 是否已完全加载 PDF 文件
【发布时间】:2014-11-29 00:03:13
【问题描述】:

如何在 iframe 加载 PDF 文件时显示加载指示器?

在我的部分工作解决方案中,我执行以下操作:当 iframe 所在的模式对话框打开时,会出现一个加载指示器。如果 iframe 的内容已完全加载,则指示器会消失并显示 PDF 文件。

这是我的代码:

<div data-gid="<?php echo $gid; ?>" class="modal fade" id="sammelPDF" tabindex="-1" role="dialog" aria-labelledby="sammelPDF" aria-hidden="true">
    <div class="modal-dialog" style="width: 1000px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Wettkampfplan gesamt</h4>
            </div>
            <div class="planGesamtModalBody modal-body">
                <div class="rwk-progress" style="display: table; margin: 0 auto;">
                    <div style="text-align: center;">
                        <img src="/planung/images/spinner.gif" />
                    </div>
                    <p style="margin-top: 10px; text-align: center;">Bitte haben Sie etwas Geduld...</p>
                </div>
                <iframe width="100%" height="100%" frameborder="0" allowtransparency="true" id="planGesamtPDFFrame" src=""></iframe>
            </div>
        </div>
    </div>
</div>

$('.sammelPDFWettkampfplan').click(function() {
    $('.planGesamtPDFFrame').hide();
    $('.rwk-progress').show();
});

$('#sammelPDF').on('show.bs.modal', function() {
    var group = getActiveTab();

    var url = '/pdf?gid=' + $(this).data('gid') + '&classes=1,2,3,4&group=' + group.attr('id') + '&nocache=' + new Date().getTime();
    $('#planGesamtPDFFrame').attr('src', url);

});

$('#planGesamtPDFFrame').load(function() {
    $('.rwk-progress').hide();
    $(this).show();
});

此解决方案在 Safari、FF、Chrome 和 Opera 中运行良好,但在 IE 中不适用。 如何实现加载指示器隐藏而 PDF 显示在 IE 中?

在 Google 中,我发现了一些关于 onreadystatechangereadyState 的有趣帖子,但这也不起作用。

【问题讨论】:

标签: javascript jquery internet-explorer iframe cross-browser


【解决方案1】:
var iframe = document.createElement("iframe");
iframe.src = "simpleinner.htm";

if (iframe.attachEvent){
    iframe.attachEvent("onload", function(){
        alert("Local iframe is now loaded.");
    });
} else {
    iframe.onload = function(){
        alert("Local iframe is now loaded.");
    };
}

http://www.nczonline.net/blog/2009/09/15/iframes-onload-and-documentdomain/

【讨论】:

  • 我刚刚尝试了您的解决方案,但它不起作用:(当我添加 else ififrame.addEventListener 时,选择了此分支,但似乎事件的回调方法是'未执行。
猜你喜欢
  • 2012-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-18
  • 2018-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多