Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear the content of an IFRAME?

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.

like image 331
sikender Avatar asked Nov 23 '09 18:11

sikender


People also ask

How to clear iframe content?

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.

What is #document in 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.

How do you hide an iframe in HTML?

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.

Can you mute an iframe?

An iframe does not have an audio API, so you can't mute anything using JS on that element.


2 Answers

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.

like image 146
McKay Avatar answered Sep 29 '22 03:09

McKay


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 :)

like image 43
Bogdan Avatar answered Sep 29 '22 03:09

Bogdan