基于根据搜索结果更改大小的内容的iframe自动调整大小 [英] iframe auto size based on content that changes size based on search results

查看:112
本文介绍了基于根据搜索结果更改大小的内容的iframe自动调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面包含搜索页面iframe。如果您尝试搜索文本,它很少适合页面。

I have one page that contains search page iframe . If you try to search for a text it will rarely fit the page.

我不知道根据内容变化自动调整iframe大小的代码。

I don't know what code to use to auto resize iframe based on content changes.

现在我在iframe中使用此代码:

Right now I use this code in iframe :

 <body onload="parent.alertsize(document.body.scrollHeight);">

这个javascript在父页面中:

And this javascript in parent page :

 <script>
function alertsize(pixels){
 pixels+=32;
 document.getElementById('my-iframe').style.height=pixels+"px";
 }
 </script>


推荐答案

<script type="text/javascript">
var myHeight = 0;

setInterval(function(){
    if(myHeight != document.body.scrollHeight){
        myHeight = document.body.scrollHeight;
        parent.alertsize(myHeight);
    }
},500);
</script>

这篇关于基于根据搜索结果更改大小的内容的iframe自动调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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