1

I created a div with an id "example" and the message for the modal box inside of it. The issue I am having is that the iframe with id loaded once loaded is not closing the modal box. Is there anything I am missing here?

$(document).ready(function(){
$("#example").dialog({modal: true});
});

$('#loaded').load(function() {
$("#example").dialog("close");
}); 
pcproff
  • 612
  • 1
  • 8
  • 30

2 Answers2

0

Have you tried

$("#loaded").ready(function (){
   $("#example").dialog("close");
});
Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
0

I suspect it's because the wireup for the load event is happening before the HTML is ready, try this:

$(document).ready(function(){
    $("#example").dialog({modal: true});

    $('#loaded').ready(function() {
        $("#example").dialog("close");
    }); 
});

There's a question already about getting a pdf in an iframe to notify, they didn't think it could work: How do I fire an event when a iframe has finished loading in jQuery?

Community
  • 1
  • 1
Glenn Slaven
  • 33,720
  • 26
  • 113
  • 165
  • This is a good solution and works perfectly in FF. The dialog box closes as soon as the file just hits the iframe and not when completely loaded in Chrome and IE. – pcproff Dec 02 '11 at 00:34
  • Then I would suggest adding Adam's solution & changing `$('#loaded').load` to `$('#loaded').ready` ready fires once the DOM is finished loading. I'll update my answer – Glenn Slaven Dec 02 '11 at 00:43
  • Thanks for the quick responses Adam, Glenn, Emre. Glenn, this last response works awesome but closes almost instantly on chrome and IE :( – pcproff Dec 02 '11 at 00:51
  • I tried moving out this pdf out of the iframe and no luck. I was reading around that detecting the file fully loaded in an iframe might cause an issue. – pcproff Dec 02 '11 at 02:19
  • It's a PDF loading in the iframe? I don't think you're going to get this to work, I've added a link in the answer above to a relevant question . – Glenn Slaven Dec 07 '11 at 00:15