是否有有效的跨域 iframe 高度自动调整器? [英] Is there a cross-domain iframe height auto-resizer that works?

查看:10
本文介绍了是否有有效的跨域 iframe 高度自动调整器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了一些解决方案,但没有成功.我想知道是否有解决方案,最好提供易于遵循的教程.

I tried a few solutions but wasn't successful. I'm wondering if there is a solution out there preferably with an easy-to-follow tutorial.

推荐答案

你有三个选择:

这是一个简单的库,用于保持 iFrame 的大小适合其内容.它使用 PostMessage 和 MutationObserver API,并支持 IE8-10.它还具有内容页面的选项,用于请求包含特定大小的 iFrame,并且还可以在完成后关闭 iFrame.

This is a simple library for keeping iFrames sized to their content. It uses the PostMessage and MutationObserver APIs, with fall backs for IE8-10. It also has options for the content page to request the containing iFrame is a certain size and can also close the iFrame when your done with it.

https://github.com/davidjbradshaw/iframe-resizer

Easy XDM 使用了一系列技巧来实现许多浏览器中不同窗口之间的跨域通信,并且有使用它来调整 iframe 大小的示例:

Easy XDM uses a collection of tricks for enabling cross-domain communication between different windows in a number of browsers, and there are examples for using it for iframe resizing:

http://easyxdm.net/wp/2010/03/17/resize-iframe-based-on-content/

http://kinsey.no/blog/index.php/2010/02/19/resizing-iframes-using-easyxdm/

Easy XDM 通过在现代浏览器上使用 PostMessage 和基于 Flash 的解决方案来工作作为旧浏览器的后备.

Easy XDM works by using PostMessage on modern browsers and a Flash based solution as fallback for older browsers.

另见 Stackoverflow 上的这个线程(还有其他的,这是一个常见问题问题).此外,Facebook 似乎也使用类似的方法.

See also this thread on Stackoverflow (there are also others, this is a commonly asked question). Also, Facebook would seem to use a similar approach.

另一种选择是将 iframe 高度发送到您的服务器,然后从使用 JSONP 的父网页从该服务器进行轮询(如果可能,也可以使用长轮询).

Another option would be to send the iframe height to your server and then poll from that server from the parent web page with JSONP (or use a long poll if possible).

这篇关于是否有有效的跨域 iframe 高度自动调整器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆