问题
I have some iframe:
<iframe src="/node_modules/collaborator-gallery/dist/index.html?id=3823&auto_play=true&track=true&initialWidth=1290&childId=pymd-aaeafe70-910d-494b-ac6b-e68d8eb2de66&parentUrl=http%3A%2F%2Flocalhost%3A8080%2Fresources%2Fexecute%2F20895"
width="100%" scrolling="no" marginheight="0" frameborder="0" class="embed-responsive-item" height="480px"></iframe>
through it I use the gallery. How do I get to events through another component in Angular 6
回答1:
In window A's scripts, with A being on http://example.com:8080:
`var popup = window.open(...popup details...);
popup.postMessage("The user is 'bob' and the password is 'secret'", "https://secure.example.net");
popup.postMessage("hello there!", "http://example.com");`
`function receiveMessage(event) {
if (event.origin !== "http://example.com")
return;
// event.data is "hi there yourself! the secret response is: rheeeeet!"
}`
`window.addEventListener("message", receiveMessage, false);`
Called sometime after postMessage is called
`
function receiveMessage(event) {
if (event.origin !== "http://example.com:8080")
return;
// event.data is "hello there!"
event.source.postMessage("hi there yourself! the secret response " + "is: rheeeeet!", event.origin);
}`
window.addEventListener("message", receiveMessage, false);
来源:https://stackoverflow.com/questions/52170003/how-to-get-data-from-iframe-with-angular-6