在 flutter web 中调用 iframeElement 上的 postMessage
Calling postMessage on iframeElement in flutter web
我有一个 flutter web 应用程序。我需要调用 postMessage 以由使用
在 iframe 元素中打开的页面处理
ui.platformViewRegistry.registerViewFactory(
'hello-world-html',
(int viewId) => html.IFrameElement()
..width = '100%'
..height = '100%'
..src = widget.url
..style.border = 'none'
);
有办法吗?
从技术上讲,PostMessage 发送到主文档的 window,而不是 iframe 的。
在 Javascript 中指定 iframe 的 window 对象:
document.getElementById('hello-world-html').contentWindow.postMessage(.......)
或者在 Dart 中你可以这样做:
import 'dart:html' as html;
// Your code
html.document.getElementById.getElementById('hello-world-html').contentWindow.postMessage(.......)
我有一个 flutter web 应用程序。我需要调用 postMessage 以由使用
在 iframe 元素中打开的页面处理 ui.platformViewRegistry.registerViewFactory(
'hello-world-html',
(int viewId) => html.IFrameElement()
..width = '100%'
..height = '100%'
..src = widget.url
..style.border = 'none'
);
有办法吗?
从技术上讲,PostMessage 发送到主文档的 window,而不是 iframe 的。
在 Javascript 中指定 iframe 的 window 对象:
document.getElementById('hello-world-html').contentWindow.postMessage(.......)
或者在 Dart 中你可以这样做:
import 'dart:html' as html;
// Your code
html.document.getElementById.getElementById('hello-world-html').contentWindow.postMessage(.......)