【发布时间】:2021-05-25 10:42:35
【问题描述】:
我想将我的 html 页面上 iframe 的内容设置为来自 js 中 fetch 命令的响应。我目前正在使用此代码。
window.fetch(
"https://www.youtube.com/embed/SXR0D3MzpBM?autoplay=0&mute=1", {
method: 'GET',
accept: 'text/html',
mode: 'no-cors'
})
.then(data => {
console.log(data);
var iframe = document.getElementById('video');
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(data);
iframe.contentWindow.document.close();
});
当我测试这段代码时,iframe 只是显示
[Object Response]
我想在 iframe 中查看嵌入的 youtube 视频。
【问题讨论】:
标签: javascript html iframe embed