PHP - 获取跨域 iframe 页面的初始大小?
我想知道是否有任何方法可以使用 PHP 来检测您无法控制的跨域网页的尺寸,以便(最初)将您自己网站中的 iframe 设置为正确的尺寸以显示它,而无需滚动条。
在这个问题中:
海报指出“我可以获取加载到 iframe 中的第一页的高度(使用 PHP),但无法获取后续页面的高度,因为无法知道 iframe 中的 url/位置会发生什么变化。”
有谁知道这是否真的可能以及如何做到?
I'm wondering if there is any way with PHP to detect the dimensions of a cross-domain Web page that you have no control over, so as to (initially) set an iframe in your own site to the right size to display it without scrollbars.
In this question:
Get height of iframe with external URL
The poster states "I can get the height of the first page loaded into the iframe (using PHP), but no way of getting subsequent page heights because no way of knowing what the url/location changes to in the iframe."
Does anyone know if that is really possible and how to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在其他问题中,发布者指出:
读取行间,加载的第一页iframe 必须位于同一域,也可能位于不同的域,但(至关重要的是)与包含页面位于同一开发人员的控制之下。使用 PHP 无法读取渲染页面的大小 - 客户端需要 JavaScript 来获取浏览器实际渲染的尺寸,而这超出了任何服务器端代码的控制范围。所以我不确定“使用 PHP”是什么意思。
恐怕我的答案仍然成立:它由于浏览器的安全模型,不可能获取您无法控制的跨域网页的尺寸。如果可能的话,这将是一个安全问题,必须予以修复。更多详细信息请点击此处。
In that other question, the poster states:
Reading between the lines, that first page loaded into the iframe must be on the same domain, or possibly a different domain but (crucially) under the control of the same developer as the containing page. It's not possible to read the size of the rendered page using PHP - JavaScript is needed client side to obtain the dimensions of what the browser actually renders which is outside the control of any server-side code. So I'm not sure what was meant by "using PHP".
I'm afraid my answer still holds: It is not possible to get the dimensions of a cross-domain web page that you have no control over, because of the browser's security model. If it was possible, that would be a security problem and would have to be fixed. More details here.