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