Activate iframe and change its contents

Viewed 20

I am losing my marbles over this issue:

There's an iframe that i try to programmatically manipulate, but somehow this is only possible after i go into the developer console and click a parent node.

This is the best i can come up with:

var iframes = document.getElementsByTagName('iframe');
for (var i = 0; i < iframes.length; i++) {
if (iframes[i].parentNode.id == 'cke_355_contents') {
iframes[i].contentWindow.document.open();
iframes[i].contentWindow.document.write('<html><body>Hello World</body></html>');
iframes[i].contentWindow.document.close();
 }
  }

Even if i try to list all iframes on the page:

document.querySelectorAll('iframe').forEach((iframe)=> {
  console.log(iframe.id, iframe.className, iframe.src)
});

i just get the first 2 results. But, when i click a parentnode in the console, it will only list the iframe i actually need.

Is there some way to find the correct iframe,"activate" it and manipulate it?

0 Answers
Related