I was surprised to find the following doesn't appear to work, insofar as the DOMContentLoaded
event doesn't fire (this.els
is an object of elements).
this.els.stage_ifr.prop('src', 'templates/'+ee.globals.creating+'/item'+this.id);
this.els.stage_ifr[0].addEventListener('DOMContentLoaded', function() {
alert('loaded!');
}, false);
The page loads into the iframe fine, but no callback. The DOM level zero onload
, however, works.
this.els.stage_ifr[0].onload = function() { alert('loaded!'); }; //<-- fires
A workaround is to prepare a globally-accessible jQuery deferred object in the parent page and resolve it via a DOM-ready event fired from the page called into the iframe, rather than listening for DOM-ready from the parent.
Paraent page:
dfd = new $.Deferred;
dfd.done(function() { alert("frame page's DOM is ready!"); });
Frame page:
$(function() { window.parent.dfd.resolve(); });
Nonetheless it would be good to know what's up with the first approach...
DOMContentLoaded
can't be attached to aniframe
. – DjokjakartaDOMContentLoaded
(a method ofdocument
only) tostage_ifr[0].contentDocument
, I'm just not sure, if it would exist at the time you'll need it... – Djokjakarta