代码描述:IE浏览器iframe 内存不释放。IE浏览器iframe内存不释放代码实例
在一些低版本的IE浏览器中,当用open()函数打开一个窗口的时候,如果这个窗口中有使用iframe引入其他页面,尽管打开的窗口被关闭,但是iframe引入页面的内存也不会释放,下面就分享一段能够解决此问题的代码。 代码如下:
<!DOCTYPE html><html> <head> <meta charset=" utf-8"> <meta name="author" content="https://www.51qianduan.com/" /> <title>51前端</title> <script type="text/javascript"> function unloadHandler(notip){ // 取消窗口关闭时的监听事件 document.getElementsByTagName("body")[0].onbeforeunload = null; var el = document.getElementById("scanIf"); if(el){ el.src = ""; setTimeout(cycleClear, 100); return "提示:请点击取消按钮,当前窗口会自动关闭。"; } 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.onload=function(){ window.onbeforeunload=function(){ return unloadHandler(); } } </script> </head> <body> <iframe id="scanIf" width="800px" height="600px" src = "https://www.51qianduan.com"></iframe> </body> </HTML>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能