iframe auto size based on content that changes size based on search results

泄露秘密 提交于 2019-12-13 06:20:02

问题


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

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

Right now I use this code in iframe :

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

And this javascript in parent page :

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

回答1:


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

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


来源:https://stackoverflow.com/questions/15547009/iframe-auto-size-based-on-content-that-changes-size-based-on-search-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!