davidjbradshaw/iframe-resizer

Resizing broken if iframed page loads iFrameResizer.contentWindow.js asynchronously

caseyhoward opened this issue · 4 comments

I'm having an issue where the host page is sending messages to the iframed page too soon. I even moved the iFrameResize call to the onload handler for the iframe. That doesn't work, because even at the time the iframed page is loaded, the message handler hasn't been set up yet (iFrameResizer.contentWindow.js hasn't loaded). We are using requirejs to load the javascript file, so it loads asynchronously.

Right now I just wrapped the call to iFrameResize in a setTimeout with an arbitrary wait of 1 second. It would be nice if I didn't have to worry about this as the solution I came up with is non-optimal and could still potentially not work. Is this an issue you have addressed before? Is there a better solution than what I did?

This is a new one on me. The message is sent when the onload event of the iFrame is fired, you should not bind this directly to the iFrame yourself.

I expect the issue is that your script loader, is loading the scripts after the document ready event has fired in the iFrame. If so, then I would consider that to be a bug in require.js.

So in summary, whilst you can use require.js on the parent page, in the iframe you need to include it inline at the end of the page.

I expect the issue is that your script loader, is loading the scripts after the document ready event has fired in the iFrame. If so, then I would consider that to be a bug in require.js.

Asynchronous loading is a feature of require.js, not a bug. Anyway, I do realize I can put your script at the bottom of the page, but that's not really how I would like to use the library. It would be nice if I didn't have to treat it special from the other javascript libraries I use. One solution would be to have the host page ping the iframe until it was ready.

Please feel free to submit a patch, with a test script for this.