How do I clear the content of my IFRAME element, using javascript, without loading a blank page into it?
I can figure out to do this: iframe_element.src = "blank.html"
, but there must be a better, instant, method.
To clear the content of an iframe with JavaScript, we call write to write an empty string. const iframe = document. getElementById("myiframe"); const html = ""; iframe.
Definition and Usage. The contentDocument property returns the Document object generated by a frame or iframe element. This property can be used in the host window to access the Document object that belongs to a frame or iframe element.
The hidden attribute hides the <iframe> element. You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <iframe> is not visible, but maintains its position on the page.
An iframe does not have an audio API, so you can't mute anything using JS on that element.
about:blank
is a "URL" that is blank. It's always clear
You can set the page's source to that, and it will clear.
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 did it :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With