<! DOCTYPE html>
Online transmission, the following wording to reduce memory leaks:
var framedom = $ (' iframe:eq (0) ') [0]; var framewin = Framedom.contentwindow; try{FrameWin.document.write ("); FrameWin.document.clear (); }catch (e) {}; FRAMEDOM.SRC = ' b.html ';
So what's the effect?
One: Set the URL directly
var flag = true; var framedom = $ (' iframe:eq (0) ') [0]; $ (' button '). On (' Click ', function () {&NBSP;&NBSP;IF (flag) { var framedom = $ (' iframe:eq (0) ') [0]; var frameWin = frameDom.contentWindow; /* Try{ framewin.document.write ('); FrameWin.document.clear (); }catch (e) {}; */ frameDom.src = ' b.html '; flag = false; }else{ var framedom = $ (' iframe:eq (0) ') [0]; var frameWin = frameDom.contentWindow; /* Try{ framewin.document.write ('); FrameWin.document.clear (); &nBsp; }catch (e) {}; */ framedom.src = ' a.html '; flag = true; } //$ (' # Console '). Append (flag ? ' Switch to a.html ': ' Switch to b.html '); });
Use the Sieve test: #leaks增加28左右 each time you switch.
Two: According to the network to send the wording
<script> var flag = true; var framedom = $ (' iframe:eq (0) ') [0]; $ (' button '). On (' click ', Function () {&NBSP;&NBSP;IF (flag) { var framedom = $ (' iframe:eq (0) ') [0]; var framewin = frameDom.contentWindow; try{ framewin.document.write ('); framewin.document.clear (); }catch (e) {}; framedom.src = ' b.html '; flag = false; }else{ var framedom = $ (' iframe:eq (0) ') [0]; var framewin = framedom.contentwindow; try{ framewin.document.write ('); framewin.document.clear (); }catch (e) {}; frameDom.src = ' a.html '; flag = true; } //$ (' #console '). Append (flag ? ' Switch to a.html ': ' Switch to b.html '); });</script>
Use the Sieve test: #leaks增加28左右 each time you switch. There's no difference between writing and writing.
Three:
var flag = true; var framedom = $ (' iframe:eq (0) ') [0]; $ (' button '). On (' Click ', function () {&NBSP;&NBSP;IF (flag) { /* try{ framedom.contentwindow.document.write ('); FrameDom.contentWindow.document.clear (); framedom.contentwindow.close (); }catch (e) {}; */ $ (' iframe:eq (0) '). Remove (); $ (' body '). Append ("<iframe Src= ' b.html ' ></iframe> '); flag = false; }else{ /* try{ framedom.contentwindow.document.write ('); framedom.contentwindow.document.clear (); FrameDom.contentWindow.close (); }catch (E) {}; */ $ (' iframe:eq (0) '). Remove ( ); $ (' body '). Append ("<iframe src= ' a.html ' ></iframe>"); flag = true; } });
Using the Sieve test: #leaks平均为 3, which is significantly different from the first two
Four: Notice that the three comments in the code of a paragraph, remove the comment?
var flag = true; var framedom = $ (' iframe:eq (0) ') [0]; $ (' button '). On (' Click ', function () {&NBSP;&NBSP;IF (flag) { try{ FrameDom.contentWindow.document.write ("); framedom.contentwindow.document.clear ( ); framedom.contentwindow.close (); } catch (E) {}; $ (' iframe:eq (0) '). Remove (); $ (' body '). Append ("<iframe src= ' b.html ' ></iframe>"); flag = false; }else{ try{ framedom.contentwindow.document.write ('); FrameDom.contentWindow.document.clear (); framedom.contentwindow.close (); }catch (e) {}; $ (' iframe:eq (0) '). Remove (); $ (' body '). Append ("<iframe src= ' a.html ' ></iframe>"); flag = true; } });
This writing and writing 3 does not differ significantly, each switch #leaks still increase by about 3
So it can be concluded that the best solution to resetting the IFRAME address memory leak is to kill it and add one!
The internet doesn't have to be reliable.
Note: The native test environment is WIN7 x64 IE9
Resolution of memory leaks when using jquery to reset an iframe address under IE