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

162
Views
Iframe contentWindow getElementById Question

First, my iframe page is in same domain (in the same project of parent). I tried to get the element by id of the iframe. This is my /views/index.html

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/functions" prefix = "fn" %>
<!DOCTYPE html>
<html>
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
<title>SubWay</title>

</head>
<body>
    
    
    <iframe src="/test" id="test"></iframe>
    
    <script>
    console.log(document.getElementById("test").contentWindow.document.getElementById("test));
    </script>
    
    
</body>
</html>

This is my iframe, which is /views/test.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<div id="test">test</div>
</body>
</html>

So, simply, I tried to get the div from test.jsp in the index.jsp. iframe shows up in the index.jsp. However, as I tried to print console.log(document.getElementById("test").contentWindow.document.getElementById("test)); console shows null. Yet, "document.getElementById("test").contentWindow.document" this is not null;

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!