Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
JS: iFrame contentWindow returns null

I want to call a function when a button within an iframe is clicked, but I am already having problems accessing the iframe document.

First, I followed this video, but null is returned when the function is called. The iFrame's content is hosted on the same server, using a wordpress installation in a folder (mydomain.com/fragen). The main page is mydomain.com, so that should not be the issue, right? Here is the code I was using. Printing a string to the console works.

<button onclick="test()">Test</button>

<iframe id="myIframe" src="mydomain.com/fragen/wp-admin/admin-ajax.php?action=h5p_embed&id=24" width="100%" height="525" frameborder="0" allowfullscreen="allowfullscreen" title="Diagnosetext">
</iframe>

<script>
const myIframe = document.querySelector("#myIframe");

function test() {
    const iframeWindow = myIframe.contentWindow;
    console.log(iframeWindow);
}
</script>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!