Closed jameswragg closed 4 years ago
I gave the iframe a generated name & it seemed to fix it!
Thanks for the information @jameswragg. I'm glad you got it working. I tried to reproduce your example because I was curious about it, but things seem to be working for me. Here's my setup: http://dtm.aaronhardy.com/penpal/
Did I miss something?
Thanks for coming back to me even though its working :)
The only difference is I'm creating the iframe & appending to the body, writing the contents in the onload callback but thats minimal difference & can only assume I was doing something silly as its working correctly now.
Using Penpal because I can apply it to any iframe, my goto for postmesaging (postmate) has to create the iframe itself. Glad I was forced to make the switch, really enjoying using it!
Thanks @jameswragg! I appreciate the kind words.
I'm creating an iframe with JS, building my own document (with Penpal in head) and writing it in, the iframe loads but Penpal fails with:
connectToParent() must be called within an iframe
when it actually is and the parent has Penpal running and listening.The check that's failing is here: https://github.com/Aaronius/penpal/blob/master/src/connectToParent.js#L32
I can only assume window does equal window.top when the document has been built from the parent.
Here's a poor test-case on jsbin: https://jsbin.com/huhocig/5/edit?html,js,output
Poor because jsbin uses iframes, so the condition is met but hopefully you'll get the gist of how I'm building my iframe.
Is there a way around this, or can the check be disabled? If I manually comment out the check - everything works as expected.