Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda