Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
caseyhoward opened this issue Oct 2, 2014 · 4 comments

Comments

@caseyhoward
Copy link

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?

@davidjbradshaw
Copy link
Owner

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.

@davidjbradshaw
Copy link
Owner

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.

@caseyhoward
Copy link
Author

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.

@davidjbradshaw
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants