如何使用Angular 6从iframe获取数据 [英] How to get data from Iframe with Angular 6

查看:524
本文介绍了如何使用Angular 6从iframe获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些iframe:

I have some iframe:

<iframe src="/node_modules/collaborator-gallery/dist/index.html?id=3823&amp;auto_play=true&amp;track=true&amp;initialWidth=1290&amp;childId=pymd-aaeafe70-910d-494b-ac6b-e68d8eb2de66&amp;parentUrl=http%3A%2F%2Flocalhost%3A8080%2Fresources%2Fexecute%2F20895"
width="100%" scrolling="no" marginheight="0" frameborder="0" class="embed-responsive-item" height="480px"></iframe>

通过它我使用图库. 如何通过Angular 6中的另一个组件获取事件

through it I use the gallery. How do I get to events through another component in Angular 6

推荐答案

在窗口A的脚本中,其中A位于 http://example.com:8080 :

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);`

在调用postMessage之后的某个时间调用

`

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);

这篇关于如何使用Angular 6从iframe获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆