[英]resize iframe height on different domain
I am allowing a part of my site to be shown in another site (different domain). 我允许我的网站的一部分显示在另一个网站(不同的域)中。
My concern is to set the height of iframe to the height of its content. 我的担心是将iframe的高度设置为其内容的高度。 I could use this solution , but my case is cross browser case, so this doesnot work.
我可以使用此解决方案 ,但是我的情况是跨浏览器的情况,所以这不起作用。
I tried to get the height of iframe by: 我尝试通过以下方式获取iframe的高度:
window.parent.document.getElementById('id_iframe').contentDocument.body.scrollHeight;
but this is giving only the visible height. 但这仅给出了可见的高度。
What am I missing? 我想念什么?
You can't use JavaScript to access content the user has loaded from another domain. 您不能使用JavaScript访问用户从其他域加载的内容。 It would be a security risk.
这将带来安全风险。
With the cooperation of the other site, you can receive a message (via postMessage
) sent by the other site when its load
event fires that tells you its height (and then you can resize in response to that). 在另一个站点的合作下,当另一个站点的
load
事件触发时,您可以接收到另一个消息(通过postMessage
),该消息告诉您其高度(然后您可以根据其大小进行调整)。
It could also sent new heights when resize
events fire in it. 当
resize
事件触发时,它也可能发送新的高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.