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

How can i post message to iframe? #13

Closed
depomguss opened this issue Aug 4, 2019 · 1 comment
Closed

How can i post message to iframe? #13

depomguss opened this issue Aug 4, 2019 · 1 comment

Comments

@depomguss
Copy link

depomguss commented Aug 4, 2019

My parent Vue:

<vue-friendly-iframe
:style="{ 'display' : iframeLoading ? 'none' : 'block' }"
:src="example1Form.src "
@load="onLoad"
@iframe-load="onIframeLoad"
@document-load="onDocumentLoad"
frameborder="0"
gesture="media"
allow="encrypted-media"
allowfullscreen="allowfullscreen"
width="100%"
ref="friendlyIframe"
>

My parent send post message function:

sendPostMessage() {
this.$refs.friendlyIframe.iframeEl.contentWindow.postMessage("message");
}


My Iframe (Html):

<script> window.addEventListener("message", function (event) { alert() <---------- not working }, false); </script>
@officert
Copy link
Owner

I think you need to provide the targetOrigin argument when calling window.postMessage()

https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#Syntax

this.$refs.friendlyIframe.iframeEl.contentWindow.postMessage("message", "*"); //note the *

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