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

最新文章

  1. MySQL 第一篇
  2. 从零开始---控制台用c写俄罗斯方块游戏(1)
  3. Supervisor 的配置与使用
  4. UNITY3D在IOS开发下的反射机制限制
  5. 自定义cell
  6. 使用 Environment Indicator 模块区分不同的 Drupal 环境
  7. Find mac address
  8. Android 和 PHP 之间进行数据加密传输
  9. freemarker报错之三
  10. Mac 配置Charles,抓取移动设备数据
  11. Spark SQL UDAF示例
  12. JDK8新特性03 Lambda表达式03_Java8 内置的四大核心函数式接口
  13. 【netcore基础】CentOS 7.6.1810 搭建.net core 2.1 linux 运行环境 nginx反向代理 supervisor配置自启动
  14. 牛客网NOIP赛前集训营-提高组(第一场)A 中位数
  15. C语言中右大括号(})后是否加分(;)号问题
  16. node基于express的socket.io
  17. Git和Github入门
  18. Linux内核(6) - 模块机制与“Hello World!
  19. python获取当天日期进行格式转换
  20. C++ 文件类型分析

热门文章

  1. deque!
  2. Python中re模块详细介绍
  3. ionic生成签名的APK方法总结
  4. 设置pdsh的默认登录模式
  5. java学习(五)Number类、Math类
  6. SICP读书笔记 3.5
  7. windows上的mysql配置过程
  8. XML学习(一)
  9. Netty源码分析第1章(Netty启动流程)----&gt;第3节: 服务端channel初始化
  10. QRCode 二维码