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


i have 1 page contains search page iframe . if try search text fit page.

i don't know code use auto resize iframe based on content changes.

right use code in iframe :

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

and 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> 

Comments