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 ...
随机推荐
- jsp 中 , jq 获取当前所点击的 select 的 id 值的注意事项
因为是使用的 jstl 的 foreach ,所以每个 select 的 id 值都不同,要想在 change 方法中获取到 当前所点击的 select 的 id 值,需要注意的地方有: 1. 得到 ...
- Python 学习 第五篇:语句和语法
Python程序是语句构成的,语句包含表达式,表达式嵌套在语句中,包含变量和常量,用于处理对象.Python的语法实质上是由表达式.语句和代码块构成的.语句是由表达式构成的,代码块是由多个语句构成的复 ...
- mybatis学习(一)-------XML 映射配置文件详解
XML 映射配置文件 MyBatis 的配置文件包含了会深深影响 MyBatis 行为的设置(settings)和属性(properties)信息.文档的顶层结构如下: configuration 配 ...
- TCP Over HTTP 的Buffer问题
记录下备忘. 场景:要把TCP拆成一个个HTTP请求,通过Proxy 1.HTTP Client上载数据到CCProxy ,然后再到Web服务器的时候. 如果数据量比较小,例如10个字节,Proxy就 ...
- eclipse检出SVN代码的详细流程
1.添加SVN资源库位置(未安装SVN,请先安装SVN) 2.因为该项目不是maven项目 所以还需要加入jar包(将项目lib里面的jar都Buile Path) 3.我这个项目需要修改编码格式 右 ...
- 多个EXCEL文件合并成一个
Python的numpy处理起来会比较方便,有空实现一下,这里是Excel内部代码的方式: 合并方法如下: 1.需要把多个excel表都放在同一个文件夹里面,并在这个文件夹里面新建一个excel.如图 ...
- 出现 org.springframework.beans.factory.BeanCreationException 异常的原因及解决方法
1 异常描述 在从 SVN 检出项目并配置完成后,启动 Tomcat 服务器,报出如下错误: 2 异常原因 通过观察上图中被标记出来的异常信息,咱们可以知道 org.springframework.b ...
- Cocos2dx源码赏析(1)之启动流程与主循环
Cocos2dx源码赏析(1)之启动流程与主循环 我们知道Cocos2dx是一款开源的跨平台游戏引擎,而学习开源项目一个较实用的办法就是读源码.所谓,"源码之前,了无秘密".而笔者 ...
- IDEA 2018 最新激活码 License server
IDEA 2018 最新激活码 License server 总会有一个属于适合你的!嘻嘻 http://hb5.s.osidea.cc:1017 http://idea.youbbs.org htt ...
- Thunder-Final冲刺中间产物-2017秋-软件工程第十二次作业
Thunder-Final发布中间产物(WBS&PSP) WBS: 分解方式:按照「爱阅」阅读器的实施过程分解 使用工具:visio 2013 PSP: PSP 预期时间 Planning 计 ...