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.