I. Release iframe memory
According to relevant materials, IE has a bug in the collection of iframe elements. In general, you should change the src attribute value of this element to "abort: blank ", manually remove it from the DOM tree, and leave the variables referenced in the script empty and call CollectGarbage () to avoid memory leakage caused by the failure of iframe collection.
Function clearRAM (){
Var frame = document. getElementById ("ifr_content ");
Frame. src = 'about: blank ';
Frame.contentcontentdoc ument. write (''); // clear the frame content
Frame.contentmediaworkflow doc ument. clear ();
Frame. contentWindow. close (); // prevent frame memory leakage
If (navigator. userAgent. indexOf ('msie ')> = 0 ){
If (CollectGarbage ){
CollectGarbage (); // dedicated to releasing memory for IE
// Delete the original tag
Var tags = document. getElementById ("ifrSet ");
Tags. removeChild (frame );
// Add a frameset framework
Var _ frame = document. createElement ('framework ');
_ Frame. src = '';
_ Frame. name = 'content ';
_ Frame. id = 'ifr _ content ';
Tags. appendChild (_ frame );
}
}
}
// Active release once every 5 seconds
SetInterval (function (){
If (navigator. userAgent. indexOf ('msie ')> = 0 ){
If (CollectGarbage ){
// Alert (1)
CollectGarbage (); // dedicated to releasing memory for IE
}
}
},5000 );
II. iframe highly adaptive
Many people have been plagued by the highly adaptive problem of iframe, which has been encountered many times in the project. There are also a lot of related code on the Internet, but they cannot meet their own requirements.
This code mainly solves the problem that the outermost scroll bar dynamically changes with the iframe height. If the iframe height is relatively large, the outermost layer will display a scroll bar, otherwise it will not. The problem with many examples on the internet is that iframe only keeps the maximum height so that the page content height is very small, but there is a scroll bar on the right.
Compatibility: Google, Firefox, ie8 +
/**
* Iframe adaptive height, which is the minimum manual height
*/
Function initIframeHeight (height ){
Var userAgent = navigator. userAgent;
Var iframe = parent.doc ument. getElementById ("contentIframe ");
Var subdoc = iframe. contentDocument | iframe.content?#doc ument;
Var subbody = subdoc. body;
Var realHeight;
// Special processing by Google
If (userAgent. indexOf ("Chrome")>-1 ){
RealHeight = subdoc.doc umentElement. scrollHeight;
}
Else {
RealHeight = subbody. scrollHeight;
}
If (realHeight $ (Iframe). height (height );
}
Else {
$ (Iframe). height (realHeight );
}
}