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.
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.
Or you can do this :
// First I get the window from its Id.
// Then I clear it by setting the body tag inner HTML to an empty string.
// Now when I write my new content it does not get appended to the end of the body and the iframe body will contain only fresh content.
Just get the Iframe and remove the documentElement from it. The Iframe will be blank
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).
I have had difficulties with "about:blank" on pages with many IFrames. It does not seem to be a valid location in every browser (I never found out for sure, though). Anyway, I am happy with
javascript:void(0);