Answers
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.
Ric
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
windowRef.document.open();
windowRef.document.close();
should do it.
Sep 03, 2006 - 11:59 AM
so if I have
and
!
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:
Then access it in javascript like this:
x = window.frames["iframetest"];
(Or in IE just like this: x = iframetest)
Then you can do like theDude suggests:
x.document.open();
x.document.close();
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"
target="frame">clear</a>
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 - 02: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 :) |
Jan 23, 2020 - 12:36 AM
You could also do this:
<html>
<head>
<script>
var doc = null;
window.onload = function() {
alert("Filling IFrame");
doc = document.getElementById("test");
if( doc.document ) {
document.test.document.body.innerHTML = "<h1>test</h1>"; //Chrome, IE
}else {
doc.contentDocument.body.innerHTML = "<h1>test</h1>"; //FireFox
}
setTimeout(function() {
alert("Clearing IFrame");
if( doc.document ) {
document.test.document.body.innerHTML = ""; //Chrome, IE
}else {
doc.contentDocument.body.innerHTML = ""; //FireFox
}
}, 1000);
};
</script>
</head>
<body>
<iframe id="test" name="test">
</iframe>
</body>
</html>
I hope this helps!
Ruskin | Admin
Apps4Rent | o365cloudexperts
Source: IFRAME
Add New Comment