Recently, the project team found that if the IFrame object is included in the pop-up form using showModalDialog, the memory resources occupied by the IFrame object will not be released after the form is closed. After the pop-up close is repeated many times, the IE browser's memory usage can exceed hundreds of M. In severe cases, the IE browser reports an error and cannot be closed. You can only restart the browser by killing the process. After testing, this problem also exists when popping up using the open method.
In IE8 browser, there is a difference in memory usage popups from open and showModalDialog:
The form popped up in the open method occupies an independent iexplorer.exe process;
The form popped up in showModalDialog mode uses the same iexplorer.exe process as the parent form;
After searching, I found that the solution is to delete the IFrame object from the form before the form is closed. The code is as follows:
<span style="font-size:18px">var el = document.getElementById("scanIf");el.src="";el.contentWindow.document.write('');el.contentWindow.document.clear();var p = el.parentNode;p.removeChild(el);</span>However, during the test, I found that there were two limitations:
1. If el.src may not be executed yet, the following statement will be executed. If the IFrame contains cross-domain content, it will prompt that there is no permission;
2. The form is closed faster than the script is executed, and the memory is still not released;
After modification, the final script is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE></TITLE><BODY onbeforeunload="return unloadHandler();"><IFRAME id="scanIf" src = "http://www.baidu.com"></IFRAME><SCRIPT type="text/javascript">function unloadHandler(notip) {// Cancel the listening event when the window is closed document.getElementsByTagName("BODY")[0].onbeforeunload = null;var el = document.getElementById("scanIf");if (el) {el.src = "";setTimeout(cycleClear, 100);return "Tip: Please click the Cancel button, and the current window will close automatically.";}return true;}function cycleClear() {try {var el = document.getElementById("scanIf");if (el) {el.contentWindow.document.write('');el.contentWindow.document.clear();var p = el.parentNode;p.removeChild(el);}window.close();} catch (e) {setTimeout(cycleClear, 100);}}//window.onunload = unloadHandler;</SCRIPT><input type="button" value="remove" onclick="unloadHandler();"></BODY></HTML>