Jul 12, 2006 - 03:53 PM
You could always set the style display: none to it...it wouldn't actually "clear" the iframe, but it would hide it from view.
document.getElementById(iframe).style.display = none; should do the trick...
Past that, loading the iframe with a blank document would be about the only way to "clear" it out.
Aug 24, 2006 - 11:21 PM
Here's another possibility:
If "windowRef" is a reference to the window object of the frame you want
to close, then
should do it.
Sep 03, 2006 - 11:59 AM
so if I have
how do I get the reference to the window object of that iframe in order to clear it with the "open/close" sequence?
Sep 06, 2006 - 11:11 AM
First, give the iframe a name attribute instead of the id:
x = window.frames["iframetest"];
(Or in IE just like this: x = iframetest)
Then you can do like theDude suggests:
But this more simple method also works:
x.document.body.innerHTML = "";
These solutions have been tested in Firefox 1.5 and Internet Explorer 6.
Sep 14, 2014 - 10:31 AM
<a href="about:blank" rel="nofollow"
edit:/ oh you want to edit an iframes content.
ermmm... i know how to do this.
er like try
<iframe id="box" blah></iframe>
var boxy = getElementsById("box");
boxy.document.value = textareaname.value;
Feb 01, 2015 - 03:59 PM
Your technique is the most robust. Its the one I use myself. At times content may be delivered over HTTPS and the use of about:blank can cause warning messages to appear to the effect of "do you want to include content from unsecure location" or some such thing.
Something being instant is a matter of perception however if you have a single Blank.html file on your site configured with a long cache expiry the client will only ever fetch the page once (at the most once per-session).
`var iframe = document.getElementById("myiframe"); var html = "";
iframe.contentWindow.document.open(); iframe.contentWindow.document.write(html); iframe.contentWindow.document.close();`
// tested in IE, Firefox and Chrome ... it didit :)