如何根据iframe中的动态conent来改变iframe的高度? [英] How to change height of iframe based on dynamic conent within the iframe?

查看:169
本文介绍了如何根据iframe中的动态conent来改变iframe的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有动态内容的iframe。如果答案具体问题,附加信息显示(隐藏的div变得可见)。我想要扩展iframe的高度。我知道这个问题在这里被多次询问,但是似乎通常是加载iframe中的不同页面时,而不是内容在iframe内动态更改。



这是一个我试图使用jsFiddle放在一起的例子:



iframe: http://jsfiddle.net/B4AKc/2/



页面: http://jsfiddle.net/PmBrd/



任何想法?



http://jsfiddle.net/PmBrd/1/



代码:

  var iframe = document.getElementById(ifr)。contentWindow; 

iframe $(。toggle_div)。bind(change,function(){
$(#ifr)css({
height:iframe $(body)。outerHeight()
});
});

既然你提到他们在同一个域中,这只是一个类似于你真实的事情app。


I have an iframe that has dynamic content. If the answers specific questions, additional information displays (hidden div becomes visible). I'd like the height of the iframe to expand. I know this question has been asked on here multiple times, but it seems like it is typically when a different page within the iframe is loaded, not when content is changed dynamically within the iframe.

Here is an example I tried to put together using jsFiddle:

iframe: http://jsfiddle.net/B4AKc/2/

page: http://jsfiddle.net/PmBrd/

Any ideas?

解决方案

Does this work for you?

http://jsfiddle.net/PmBrd/1/

Code:

var iframe = document.getElementById("ifr").contentWindow;

iframe.$(".toggle_div").bind("change", function () {
    $("#ifr").css({
        height: iframe.$("body").outerHeight()
    });
});

Since you mentioned they are in the same domain, it's just a matter of doing something similar with your real app.

这篇关于如何根据iframe中的动态conent来改变iframe的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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