How to clear the content of an IFRAME?

Viewed 103263

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.

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

Just do it:

var iframe = document.getElementById("iframe");
iframe.removeAttribute('srcdoc');

Work in Chrome

Related