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

200
Visualizações
Get all iframes in parent window having same origin from an iframe

I have a page in which I'm including iframes from two different domains i.e. like below

<!-- domain 1 frames -->
<iframe src="domain1/page1.html">
<iframe src="domain1/page2.html">

<!-- domain 2 frames -->
<iframe src="domain2/page1.html">

Now let's say I have the below javascript code in domain1/page1.html

var frames = window.parent.frames;

This will give me all iframes (iframe from domain 1 & domain 2) from parent windows. However, I want to get only iframes from domain 1. When I try to filter iframes from only domain 1 using the below code

var isSameOrigingIframe = window.location.host == window.parent.frames[i].location.host;

I receive a security exception (Cross-origin policy violation) as an iframe from domain 1 tries to access iframe domain 2.

My current solution relies on try-catch block as below

var isSameOrigingIframe = false;
try{
   isSameOrigingIframe = window.location.host == window.parent.frames[i].location.host;
}catch(e){
   isSameOrigingIframe = false;
}

The above solution works but is there is any safe way to get iframes only from the same domain? Or there is a better way to filter out iframes from the same domain.

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