在视频网站中做节目怎么挣钱,建设网站目的及功能定位,怎么用linux做网站,自己做网站需要固定ip吗一、iframe下的#document是什么
#document 是一个特殊的 HTML 元素#xff0c;表示 iframe 元素内部的文档对象。当你在 HTML 页面中嵌入一个 iframe 元素时#xff0c;浏览器会创建一个新的文档对象来表示 iframe 内部的内容。这 个文档对象就是 #…一、iframe下的#document是什么
#document 是一个特殊的 HTML 元素表示 iframe 元素内部的文档对象。当你在 HTML 页面中嵌入一个 iframe 元素时浏览器会创建一个新的文档对象来表示 iframe 内部的内容。这 个文档对象就是 #document。
二、如何获取#document下的内容
1. 使用 contentDocument 属性
var iframe document.getElementById(myIframe);
var iframeDocument iframe.contentDocument;
// 现在可以访问 iframe 文档中的元素了
var heading iframeDocument.getElementsByTagName(h1)[0];
console.log(heading.textContent);2. 使用 contentWindow.document
var iframe document.getElementById(myIframe);
var iframeDocument iframe.contentWindow.document;
// 访问 iframe 文档中的元素
var heading iframeDocument.getElementsByTagName(h1)[0];
console.log(heading.textContent);注意如果 iframe 加载的页面与父页面不同源即协议、域名或端口任一不同则出于安全考虑浏览器的同源政策会阻止你访问 iframe 的内容。这种情况下contentDocument会返回null。 三、如何获取跨域iframe的#document里的内容
网络上有其他解决方案这里我提供一个修改chromium源码的方案。这里假设你已经可以熟练编译chromium源码。
1.找到源码
打开\third_party\blink\renderer\core\html\html_iframe_element.idl
[CheckSecurityReturnValue] readonly attribute Document? contentDocument;2.替换为
//[CheckSecurityReturnValue] readonly attribute Document? contentDocument;
readonly attribute Document? contentDocument;注意这里就是把[CheckSecurityReturnValue]这段注释掉了意思是忽略掉安全隔离。 3.编译
ninja -C out/Default chrome4.启动时加上参数必须
--disable-site-isolation-trials操作完后就可以发现跨域iframe的#document里的内容也可以获取到啦。 四、风险
1.取消跨域隔离有一定安全风险。2.有些站会做安全隔离检测可能会被识别到。 如果有更好方案请留言哈。