question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow postMessage communication

See original GitHub issue

It’d be great to be able to make use of HTML’s postMessage API to enable cross origin comms between the iFrame and the parent page. Particularly useful for the use of a lot of Payment forms where you need to securely pass some info between your page and the iFrame.

Might require some re-tooling to work with DOM and iFrame loading. Perhaps it could be an option in the onLoad function?

https://javascript.info/cross-window-communication

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
robbestadcommented, Apr 17, 2019

All right, I’ll fix this. 😃

ons. 17. apr. 2019 kl. 01:08 skrev Juan Carlos Valerio < notifications@github.com>:

@svenanders https://github.com/svenanders I was abe to implement this use case (@conorot https://github.com/conorot) in previous versions v1.5.0 to v1.6.2

But this is not supported anymore because since v1.7.0. I guest you migrate the implementation from PureComponent to Stateless or Function Component

Since then this warning is fire by React Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()

And I’m not able to get a reference.

This works on v1.6.2 but not in 1.7.0

import React from ‘react’ import { Button } from ‘antd’

export default class DemoComponent extends React.PureComponent { formRef = { iFrame: null, }

handleSubmit = () => { const { iFrame } = this.formRef if (iFrame && iFrame.refs) { const ref = iFrame.refs.iframe ref.contentWindow.postMessage(‘submit form’, ‘*’) } }

render() { return ( <div> <Iframe url="SOME_URL" width="100%" height="600px" id="legacyEditor" display="initial" position="relative" allowFullScreen ref={this.saveIFrameRef} /> <Button key="submit" type="primary" onClick={this.handleSubmit}> {‘Send message to the IFrame’} </Button> </div> ) } }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/svenanders/react-iframe/issues/43#issuecomment-483876272, or mute the thread https://github.com/notifications/unsubscribe-auth/ABfQp05TYgYEwBVIOyqo5ITEn1iEJoa0ks5vhlgGgaJpZM4a028B .

– Mvh, Sven Anders Robbestad http://www.robbestad.com http://twitter.com/#!/svenardocom

1reaction
robbestadcommented, Apr 10, 2019

All right, will look at this next!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Window.postMessage() - Web APIs | MDN
The window.postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it ...
Read more >
Cross-window communication - The Modern JavaScript Tutorial
The postMessage interface allows windows to talk to each other no matter which origin they are from. So, it's a way around the...
Read more >
How do you use window.postMessage across domains?
postMessage is to allow safe communication between windows/frames hosted on different domains, but it doesn't actually seem to allow that in Chrome.
Read more >
Cross-Origin Communication with postMessage - Pine
With postMessage(), you don't need similar protocol, host or port to send a message to other domains code. Using this function, you can...
Read more >
Using JavaScript and window.postMessage() - In Plain English
The window.postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found