Is there a cross-domain iframe height auto-resizer that works?

后端 未结 7 2398
暖寄归人
暖寄归人 2020-11-27 09:41

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.

7条回答
  •  执念已碎
    2020-11-27 10:14

    You have three alternatives:

    1. Use iFrame-resizer

    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

    2. Use Easy XDM (PostMessage + Flash combo)

    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 works by using PostMessage on modern browsers and a Flash based solution as fallback for older browsers.

    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.

    3. Communicate via a server

    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).

提交回复
热议问题