如何检查 iframe 是不是已完全加载 PDF 文件

Posted

技术标签:

【中文标题】如何检查 iframe 是不是已完全加载 PDF 文件【英文标题】: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   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 的有趣帖子,但这也不起作用。

【问题讨论】:

Load event for iFrame not fired in IE 的可能重复项 我已经尝试了Load event for iFrame not fired in IE 接受的答案,但似乎在 iframe 标记完全加载时会触发 onload 事件属性。你还有其他建议吗?我真的很困惑。 你试过这个***.com/a/6455881/1877909 我刚刚尝试了您的解决方案,但它对我也不起作用:( 【参考方案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 时,选择了此分支,但似乎事件的回调方法是'未执行。

以上是关于如何检查 iframe 是不是已完全加载 PDF 文件的主要内容,如果未能解决你的问题,请参考以下文章

如何检查图片是不是已完全加载?

如何在 Web 驱动程序中检查页面是不是已完全加载?

如何使用 settimeout 函数检查谷歌地图 API 是不是已完全加载?

如何检查您的网站是不是已在 iframe 中加载并获取父 URL? [复制]

如何检测是不是加载了 iframe?

检查 iframe 内容是不是已经加载