Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this will work if the parent site is on a different origin than the iframe. The javascript API for accessing window.parent is restricted for cross origin scripting. If you look at the same-origin policy here, it lists window.parent as read only. You can try testing this by serving the iframe test page on a different port than test-site itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems to work ok when I serve the iframe.js script from a different port, and use it in test-site iframe_page? I will take another look into cross origin restriction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the past I would generally test cross origin issues by hosting a site on SGS and pointing a local iframe_test page to the hosted iframe script. If you try modifying window.parent, will that break? If it doesn't break then maybe it's not considering it as cross origin and we'll have to test on SGS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be that read-only is not as restrictive as we think. Perhaps we can't assign to properties of
window.parent
but maybe we can still invoke methods on theparent
? So definitely worth verifying as Connor outlined.If we cannot invoke
addEventListener
on theparent
here, I'm struggling to think of how we'd accomplish this item. If the parent were to add some code we could, but if the iFrame can't reliably access the parent, we can't tell when a click event happens on the parent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
connor is right, seems like there's cross origin issue with this approach when I tested with SGS site. I put up a pr with a different solution in theme that would have cross origin issue: yext/answers-hitchhiker-theme#1034.