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

110
Vistas
How would you get a src from an iframe within an iframe?

I have some code that in short, is opening an iframe (let's call it iframe1) to view a pdf file, and that pdf is being shown in an iframe itself (let's call it iframe2), I would like to be able to get the source of the iframe2 that is within an iframe1 that would be opened so that the iframe1 itself is just the src of the pdf iframe2 and not 2 different iframes. The Url's are very different.

what is the best way to do this?

I have an open_iframe function that looks something like

function open_iframe(url) {
    return '<iframe id="iframe" src="' + url + '" width=100% height=100% frameborder="0" allowfullscreen></iframe>';
}

and I am writing another function that is

function find_file_url(url) {
    let iframe = this.open_iframe(url);
    return iframe.contentWindow.document.getElementsByTagName('iframe')[0].src;
}

I also have Jquery available to use as well.

Is this something that's possible?

Is there a better approach?

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

have you attached the iframe object to your dom? In this the html tag for "iframe" instead of creating a html string , you can create the dom iframe object directly and assign attributes to them and then parse it further. As Barmar said until then it would considered as just a html string. .document.getElementsByTagName('iframe') will be a null element as it is not attached to document object.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You might try document.domain = "site.com" , I'm dealing with similar issue. This will ensure they are in the same domain

Also you can use iframe.contentWindow and iframe.contentDocument scripting to communicate inside for the nested frame.

also assign onload, errorOnload to the attributes for console tracking

iFrame onload JavaScript event

https://javascript.info/cross-window-communication

about 4 years ago · Juan Pablo Isaza Denunciar
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