4

How could I show a loading indicator while an iframe is loading a PDF file?

In my partially working solution I do the following: When the modal dialog, where the iframe is in it, is opened then an loading indicator appears. If the content of the iframe is completely loaded the indicator disappears and the PDF file is shown.

Here is my code:

<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();
});

This solution works well in Safari, FF, Chrome and Opera but not in IE. How could I achieve that the loading indicator hides and the PDF is shown in IE?

In Google I found some interesting posts about onreadystatechange and readyState but this also doesn't working.

Patrick Vogt
  • 898
  • 2
  • 14
  • 33
  • 1
    possible duplicate of [Load event for iFrame not fired in IE](http://stackoverflow.com/questions/4334520/load-event-for-iframe-not-fired-in-ie) – Ben Lesh Oct 03 '14 at 21:54
  • I have already tried the accepted answer from [Load event for iFrame not fired in IE](http://stackoverflow.com/questions/4334520/load-event-for-iframe-not-fired-in-ie) but it seems that the `onload` event-property is fired when the iframe-tag is completely loaded. Do you have any other ideas? I am really baffled. – Patrick Vogt Oct 03 '14 at 21:59
  • 1
    have you tried this http://stackoverflow.com/a/6455881/1877909 – Hitesh Oct 03 '14 at 22:01
  • I've just tried your solution but it also doesn't work for me :( – Patrick Vogt Oct 03 '14 at 22:23

1 Answers1

3
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/

Hitesh
  • 4,098
  • 11
  • 44
  • 82
  • I've just tried your solution but it doesn't work :( When I add an `else if` with `iframe.addEventListener` then this branch is selected but it seems that the callback method for the event isn't executed. – Patrick Vogt Oct 03 '14 at 22:22