当源来自外部服务器时获取 Iframe innerHTML
Get Iframe innerHTML when source is from foreign serwer
我有简单的 iframe,我想获取 iframe innerHTML。
但是当源来自外部服务器时它不起作用
浏览器出于安全原因阻止访问。
我尝试使用 header('X-Frame-Options: SAMEORIGIN');
但它没有帮助
如何告诉我的浏览器或 apache 服务器信任外国服务器。
`
<button onClick="Show()">Get Iframe Content</button>
<iframe id="myiframe" width="100%" height="100%" src="https://not,my.site"></iframe>
<script>
function Show(){
const s = document.getElementById('myiframe');
alert(s.contentWindow.document.body.innerHTML);
}
</script>`
您无法访问跨源页面。仅当 src 为 about:blank
或应用 同源策略 时,才能访问 iframe 和子 windows。
两个 windows 之间唯一允许和支持的通信方法是:window.postMessage()
and the window: Message-Event
,它提供了一种易于使用的 API 通信方式。
我有简单的 iframe,我想获取 iframe innerHTML。 但是当源来自外部服务器时它不起作用
浏览器出于安全原因阻止访问。 我尝试使用
header('X-Frame-Options: SAMEORIGIN');
但它没有帮助 如何告诉我的浏览器或 apache 服务器信任外国服务器。`
<button onClick="Show()">Get Iframe Content</button> <iframe id="myiframe" width="100%" height="100%" src="https://not,my.site"></iframe> <script> function Show(){ const s = document.getElementById('myiframe'); alert(s.contentWindow.document.body.innerHTML); } </script>`
您无法访问跨源页面。仅当 src 为 about:blank
或应用 同源策略 时,才能访问 iframe 和子 windows。
两个 windows 之间唯一允许和支持的通信方法是:window.postMessage()
and the window: Message-Event
,它提供了一种易于使用的 API 通信方式。