how to get iframe dom in js
how to get iframe dom in js
https://stackoverflow.com/questions/3999101/get-iframes-document-from-javascript-in-main-document
// iframe.contentDocument == iframe.contentWindow.document
document.getElementById('myframe').contentWindow.document;
function GetDoc(x) {
return x.contentDocument || x.contentWindow.document;
}
contentWindow
https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/contentWindow
https://www.dyn-web.com/tutorials/iframes/refs/iframe.php
https://www.dyn-web.com/tutorials/iframes/refs/parent.php
demo
https://codepen.io/webgeeker/pen/KJppBr
<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="author" content="xgqfrms">
<meta name="generator" content="VS code">
<title>iframe single testing</title>
</head>
<body>
<section>
<h1>iframe single testing</h1>
<iframe
src ="https://www.sina.com.cn/"
target="_self"
style="border: 1px solid red;"
height="500"
width="600">
<p>Your browser does not support iframes.</p>
</iframe>
<script>
// iframe onload
const getAllIframes = () => {
let iframes = [...document.querySelectorAll(`iframe`)];
console.log(`iframes.length =`, iframes.length);
iframes.forEach(
(iframe, i) => {
if(i < 10) {
console.log(`iframe =`, iframe);
}
// iframe.contentDocument || iframe.contentWindow.document
if (iframe.contentDocument) {
// old IE
console.log(`iframe.contentDocument =`, iframe.contentDocument);
// get all links
}
if (iframe.contentWindow.document) {
// new Chrome
console.log(`iframe.contentWindow.document =`, iframe.contentWindow.document);
// get all links
}
}
);
};
const removeAllIframesBlankLinks = () => {
// iframe & virtualDOM bug
let links = [...document.querySelectorAll(`a`)];
console.log(`links.length =`, links.length);
links.forEach(
(link, i) => {
if(i < 10) {
console.log(`link =`, link);
}
if (link.target) {
console.log(`link.target =`, link.target);
link.target = "_self";
}
}
);
};
setTimeout(() => {
getAllIframes();
}, 10000);
setTimeout(() => {
removeAllIframesBlankLinks();
}, 10000);
</script>
</section>
</body>
</html>
CORS
https://stackoverflow.com/questions/6170925/get-dom-content-of-cross-domain-iframe
libs ???
https://github.com/oyvindkinsey/easyXDM#readme
postMessage
https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
iframe & CSP
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe
https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/csp
https://stackoverflow.com/questions/926916/how-to-get-the-bodys-content-of-an-iframe-in-javascript
https://html.spec.whatwg.org/multipage/iframe-embed-object.html#dom-iframe-contentwindow
https://w3c.github.io/webappsec-feature-policy/#feature-policy
https://fetch.spec.whatwg.org/#concept-response-csp-list
https://www.w3schools.com/jsref/prop_frame_contentdocument.asp
CORS demo

window.frames[0].document;

https://cdn.xgqfrms.xyz/iframe/iframe-single-testing.html
https://cdn.xgqfrms.xyz/iframe/same-origin-iframe.html
iframe & HTTPS & CORS
https://iframe.xgqfrms.xyz/eapp/index.html#blog.sina.cn
how to get iframe dom in js的更多相关文章
- Jquery 方式获取 iframe Dom元素
Jquery 方式获取 iframe Dom元素 測试页面代码: <html> <head> <title>jquery方式,訪问iframe页面dom元素& ...
- 在iframe中获取本iframe DOM引用
window.frameElement 获取本iframe DOM window.frameElement.contentDocument.getElementById('id') 获取这个ifram ...
- jQuery 互相调用iframe页面中js的方法
1,子iframe内调用父类函数方法: window.parent.func(); 2,子Iframe中获取父界面的元素: $("#xx", window.parent.docum ...
- iframe中的js
iframe之间的js是不能相互访问的,iframe和父窗体之间的js也是不能相互访问的
- jquery操作iframe中的js函数
关键字:jquery操作iframe中的js函数 1.jquery操作iframe中的元素(2种方式) var tha = $(window.frames["core_content&quo ...
- Layer获取iframe的dom元素及调用iframe页的js方法
1. 父页面点击第一个按钮触发,获取子页面中的body元素,调用子页面中定义的js方法 yes : function(index,layero){ //获取iframe的body元素 var body ...
- [HTML]HTML框架IFrame下利用JS在主页面和子页面间传值
今天写的程序涉及到JS框架传值的问题,这些是我找到的一些资料 下面主页面和子页面互相传值的DEMO 如果仅仅需要子页面触发主页面的函数 仅需 [ parent.window.你的函数 ] 就可以了 D ...
- Google street、Google satellite 、百度地图Iframe切换桥接JS
1.地图切换方法 注意:父页面访问Iframe页面JS方法需根据Iframe的名字来调用如:named "mapIfame" 即 mapIfame.window.iframeFun ...
- HTML(.js) – 最简单的方式操作 DOM 的 JS 库
HTML(.js) 是一个轻量的(压缩后~2kb) JavaScript 库,简化了与 DOM 交互的方法. 这个 JavaScript 库的方法可读性很好,并具有搜索和遍历 DOM 的方法.相比 j ...
随机推荐
- 如何创建XHTML表单
首先奉上本菜曾经的作业——一张模仿智联招聘中的注册表单.虽然没有加样式显得很难看,但表单的基本要素已经具备了. 接下来进入正文,开始介绍各表单元素 form标签: 在创建表单时,第一步就是form标签 ...
- express的web server设置流程
对于express的设置,一直是拿来就用,只知其然,今天查了一下文档,记录详细过程如下. 1.实现基本常用功能需要的模块path 用来处理路径字符串拼接,设置模板路径和静态资源路径时使用cookie- ...
- 六、Django之表单和类视图-Part 4
一.表单form 为了接收用户的投票选择,我们需要在前端页面显示一个投票界面.让我们重写先前的polls/detail.html文件,代码如下: <h1>{{ question.quest ...
- 高可用OpenStack(Queen版)集群-3.高可用配置(pacemaker&haproxy)
参考文档: Install-guide:https://docs.openstack.org/install-guide/ OpenStack High Availability Guide:http ...
- FICO(费埃哲)评分系统有什么优缺点?在国内的发展怎么样?
权威回答: FICO的优点很明显: 在美国数据库较全面.一般存储有最近7-10年的个人信用记录,包括银行信用.商业信用甚至保险等. 客观性.计算机自动完成评估工作,克服人为操作的失误. 快捷性.出结果 ...
- stat命令详解
基础命令学习目录首页 原文链接:https://blog.csdn.net/yexiangcsdn/article/details/81012732 stat命令用于显示文件的状态信息.stat命令的 ...
- Python脚本文件(.py)打包为可执行文件(.exe)即避免命令行中包含Python解释器
在最近的软件工程作业中用到了将Python脚本转化为exe文件这一过程,网上各种博客介绍了很多,有些东西都不完全,我也是综合了很多种方法最后才实现的,我就把这些整理出来,希望可以帮到大家~ 一.环 ...
- Beta阶段基于NABCD评论作品
组名:杨老师粉丝群 组长:乔静玉 组员:吴奕瑶 刘佳瑞 公冶令鑫 杨磊 刘欣 张宇 卢帝同 一.拉格朗日2018--<飞词> 1.1.NABCD分析 N(Need,需求):该小 ...
- 互评Alpha版本—SkyHunter
1.根据NABCD评论作品: N(Need,需求):飞机大战题材的游戏对80,90后的人来说算是童年的记忆,可以在闲暇之余打开电脑玩一会儿.但是面向初中生,高中生的话这种PC小游戏可能不会那么适合 ...
- OO第三阶段作业总结
调研: 最早的程序设计是直接采用机器语言来编写的,或者使用二进制码来表示机器能够识别和执行的指令和数据.机器语言的优点在于速度快,缺点在于写起来实在是太困难了,编程效率低,可读性差,并且 ...