JavaScript changes iframe height causing memory overflow
学习ing
学习ing 2017-07-05 10:51:06
0
1
962

I recently worked on a project that required the use of iframes. The height of the content inside is not necessarily constant and changes. I encountered a problem today. If the height of the iframe is changed multiple times in a short period of time, it will cause memory overflow. At first, I also I thought there was something wrong with the method I wrote, so I tried many methods after searching, and found that whether it is javascript or jQuery, as long as the height of the iframe is changed multiple times in a short period of time, whether in the parent window or the iframe, it will cause memory overflow, and then The browser is stuck.
The following is a simple function to change the iframe height

function parentHeight(add) {
         var mainheight = $("body").height();
         mainheight = mainheight < 865 ? 865 : mainheight;
         $("#iframeId", parent.document).height(mainheight + add);
         }

So is there a better way to dynamically change the iframe height, or let the iframe adapt to the content height.

学习ing
学习ing

reply all(1)
迷茫
<iframe id="iFrame1" name="iFrame1" width="100%" onload="this.height=iFrame1.document.body.scrollHeight" frameborder="0" src="index.htm"></iframe>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template