Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda