gpt4 book ai didi

javascript - 无法获取iframe的内容

转载 作者:行者123 更新时间:2023-11-28 05:29:57 24 4
gpt4 key购买 nike

我正在 iframe 中加载本地 html 文档,然后尝试从脚本访问其文档。

这是 JavaScript:

let ifrm = document.getElementById('iframeid');
console.log(ifrm);
let doc = ifrm.contentWindow.document;
console.log(doc);

这是我的 iframe 的声明:

<iframe src="untitled.html" style="display:none" id="iframeid"></iframe>

这是结果: The content of head and body gets lost.

如您所见,当我尝试获取文档时,iframe 的内容消失了。我做错了什么?

最佳答案

由于某种原因,您必须等待 onload 事件。

看这里:http://plnkr.co/edit/fNEZLyWkjT952a7e3WNy?p=preview

关于javascript - 无法获取iframe的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39781897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com