The
has recently been involved in the development of a project that has a large number of calls to IFRAME on the page because the project is a rich browser-based client (RIA) application. Late test found that browser memory has been high, and open the IFRAME page more memory footprint, especially in the IE series browser. All open iframe pages even closed, memory usage has not significantly decreased, ie browser in memory footprint up to about 400M become very card. The analysis found that the IFRAME was not released, so that all the closed IFRAME occupied by the memory of the release, although not fully released, but the IFRAME memory footprint will not always grow, the entire application memory usage control around 150M.
/** * Dynamically creating an iframe * @param dom creates a container for an IFRAME that creates an IFRAME in the DOM.
The DOM can be a div, span, or other tag. * @param src IFRAME open page path * @param onload after loading the event, you can return an empty * @return the created IFrame object/function Createiframe (DOM,
SRC, onload) {//create iframe var iframe = document.createelement ("iframe") in document;
Set the style of the iframe iframe.style.width = ' 100% ';
Iframe.style.height = ' 100% ';
Iframe.style.margin = ' 0 ';
iframe.style.padding = ' 0 ';
Iframe.style.overflow = ' hidden ';
Iframe.style.border = ' None '; The OnLoad event that binds an IFRAME if (onload && Object.prototype.toString.call (onload) = = ' [Object Function] ') {if (
Iframe.attachevent) {iframe.attachevent (' onload ', onload);
}else if (iframe.addeventlistener) {iframe.addeventlistener (' load ', onload);
}else{iframe.onload = onload;
} IFRAME.SRC = src;
Load the IFRAME under the Dom Dom.appendchild (IFRAME);
return iframe;
/** * Destroys the IFRAME, releasing the memory occupied by the IFRAME.
* @param iframe needs to destroy the IFrame object/function Destroyiframe (IFRAME) {//To point the iframe to a blank page, which frees up most of the memory. IfrAME.SRC = ' About:blank ';
try{Iframe.contentWindow.document.write (");
Iframe.contentWindow.document.clear ();
}catch (e) {}//Remove the IFRAME from the page iframe.parentNode.removeChild (IFRAME); }