0

I want to remove iframe's content but keep the "iframe tag" unchanged like:

<iframe>
    <html>
    ...
    </html>
</iframe>

change to

<iframe>
</iframe>

I tried this:

var frame_node = document.getElementsByTagName("iframe")[0];
frame_node.removeChild(frame_node.firstChild);

But I got an error: frame_node.firstChild is not an object

So how to do this? thx


got the answer:

document.getElementsByTagName("iframe")[0].contentWindow.doc‌​ument.getElementsByT‌​agName("html")[0].re‌​move();
cyx
  • 103
  • 3
  • 14
  • Are you asking about HTML inside the iframe tags in the source, or inside the iframe content itself? – Alexander O'Mara Nov 04 '16 at 04:19
  • 1
    can u refere this link http://stackoverflow.com/questions/31808185/how-to-delete-html-elements-in-an-iframe-using-javascript – Varun Sreedharan Nov 04 '16 at 04:20
  • @Alexander O'Mara inside the iframe content itself, not from src – cyx Nov 04 '16 at 04:43
  • @Varun Sreedharan thanks! it works! i use this: `document.getElementsByTagName("iframe")[0].contentWindow.document.getElementsByTagName("html")[0].remove();` so... should I remove the question ? – cyx Nov 04 '16 at 04:44

0 Answers0