繁体   English   中英

如何 position 相对于父级 iframe 内的元素?

[英]How to position an element inside an iframe with respect to parent?

我正在开发一个项目,其中内容加载在 iframe 内,加载程序也存在于 iframe 内,因此当执行某些操作时,加载程序根据 ZA598E4F2AFAD9DF861FDC476F67EF252 的高度定位,但我想基于父显示, window,有没有办法或破解来解决这个问题。

这是 iframe .loaderIcon { position: fixed;top: 50%;left: 50%; } .loaderIcon { position: fixed;top: 50%;left: 50%; }

如果应该允许 iframe 内的站点操作父 window 的内容,则有一些解决方法,但如评论中所述,iframe 中的元素不可能相对于父 Z05B8C742CBD96FBF2DEZC1A354F 显示

您可以在 iframe 中使用window.parent并创建/修改托管站点上的每个元素,但前提iframe 遵循相同的来源策略

基于站点http://example.com/这些将被允许修改父级。

URL 标准作业程序 信息
http://example.com/iframe.html 是的 相同的协议、主机和端口
http://example.com/dir/inner.html 是的 相同的协议、主机和端口
https://example.com/secure.html 其他协议
http://example.com:81/dir/etc.html 其他港口
http://subdomain.example.com/dir/other.html 其他主机

If the iframe is loaded from a different origin, you can use window.parent.postMessage() to send custom events to the page hosting the iframe and capture the Message Event to handle it on the parent window and allow everything you want. 消息事件示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM