取决于PHP内容的动态iframe高度? [英] dynamic iframe height depending on PHP content?

查看:84
本文介绍了取决于PHP内容的动态iframe高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置iframe的高度以适应其内容.

How can I set my Iframe height to be dynamic to its content.

内容仅是PHP代码,无其他内容.

The content is only PHP code, nothing else.

我使用php查询数据库,然后显示一些广告.广告越多,iframe应当越高.

I use the php to query database, and then show some ads. The more ads, the higher the iframe should be.

我认为height ='100%'应该这样做,但是没有...

I thought height='100%' should do it, but no...

我读过其他《问》,但他们的解决方案对我不起作用.

I have read other Q but their solutions doesn't work for me.

建议?

谢谢

推荐答案

您必须在javascript中设置iframe的高度. JavaScript应该位于iframe内部的页面中(必须具有iframe的页面和iframe中的页面来自不同的域).

You have to set height of iframe in javascript. JavaScript should be in page inside the iframe (must be if page with iframe and page in iframe are from different domains).

a.html:

<iframe src="b.html" id="myiframe"></iframe>

b.html:

<div style="height: 500px; background:magenta;"></div>
<script>
    parent.document.getElementById('myiframe').style.height = document.body.offsetHeight+'px';
</script>

这篇关于取决于PHP内容的动态iframe高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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