Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

52
Views
Activate iframe and change its contents

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?

6 months ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.