javascript - 如何在后台脚本创建的 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
解决方案
推荐阅读
- matlab - 如何使用 UNIX 命令将文件夹插入 MATLAB 中的 .tar 文件?
- ios - 如何从 Mac 终端检查应用程序是否在 iOS 设备中运行
- c - 如何在C中获取数组参数的实际大小?
- android - 使用 Firebase 作业调度程序运行服务直到下一个计划
- avl-tree - 如何平衡 AVL 树中的悬空节点
- javascript - 更改每个选项的占位符文本
- javascript - 如何使用struts和jquery将行的值传递给单选按钮
- android-studio - 更新到 Android Oreo 后出现奇怪的编辑框
- xamarin.forms - 如何更改 Xamarin.forms 中选项卡项的大小
- asp.net-core - 来自 jsonschema 文件的 Swashbuckle 远程定义