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

114
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
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