使用 vanilla JavaScript,我将执行以下操作以将 h1
标记添加到 iframe 主体:
var doc = document.getElementById('iframe').contentWindow.document;
doc.write('<h1>Hello</h1>');
我如何使用 CycleJS 做到这一点?
最佳答案
HTML5 引入了 iframe
属性 srcdoc
接受一个 HTML 字符串:
import {iframe, makeDOMDriver} from '@cycle/dom';
// later
iframe({attrs: {srcdoc: '<h1>Hello</h1>'}})
显然这在没有 polyfill 的 IE 或 Edge 中不起作用,如前所述here .
当然还有老信任:
iframe({attrs: {src: 'myiframe.html'}})
关于javascript - 如何使用 CycleJS 将 html 插入 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38064526/