Resizing an iframe based on content

后端 未结 21 2450
南方客
南方客 2020-11-21 07:40

I am working on an iGoogle-like application. Content from other applications (on other domains) is shown using iframes.

How do I resize the iframes to fit the heigh

21条回答
  •  终归单人心
    2020-11-21 08:20

    Here is a simple solution using a dynamically generated style sheet served up by the same server as the iframe content. Quite simply the style sheet "knows" what is in the iframe, and knows the dimensions to use to style the iframe. This gets around the same origin policy restrictions.

    http://www.8degrees.co.nz/2010/06/09/dynamically-resize-an-iframe-depending-on-its-content/

    So the supplied iframe code would have an accompanying style sheet like so...

    This does require the server side logic being able to calculate the dimensions of the rendered content of the iframe.

提交回复
热议问题