首页 > 解决方案 > 如何在后台脚本创建的 iframe 中获取元素?

问题描述

我在后台脚本中创建了一个 iframe。但我不知道如何在 iframe 中获取元素。顺便说一句,该扩展程序具有访问 Web 服务器的权限。

let iframe = document.createElement("iframe");
iframe.setAttribute("id", "iframe");
iframe.setAttribute("src", "url_to_myWebServer");
document.body.appendChild(iframe);

console.log(iframe); // iframe is shown
console.log(iframe.contentDocument.getElementById("pid")); // null

标签: javascriptgoogle-chrome-extension

解决方案


推荐阅读