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

156
Visualizações
How to get reference to the iframe from which script html tag was generated?

I have small snippet that is inside iframe and generates script html tag and appends it to the window.top.document.head.

Now I want to know how do I check from within potato.js from which iframe it was generated from once it is already loaded?

<!DOCTYPE html>
    <html lang="en">
    <head>
    </head>
    <body>
        <iframe>
            <!DOCTYPE html>
            <html>
            <head>
                
            </head>
            <body>
                <script>
                    (function() {
                        var s = document.createElement('script');
                        s.setAttribute('type','text/javascript');
                        s.setAttribute('src','https://test.com/potato.js');
                        window.top.document.head.appendChild(s);
                    })();
                </script>
            </body>
            </html>
        </iframe>
    </body>
    </html>

Edit: I can not change this code inside the iframe

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

That information isn't stored automatically.

The only way I can think of would be to add an expando-prop to the script with a reference to the current window (i.e. the frame's window)…

s.sourceWindow = window;

… then read that from within potato.js …

const sourceWindow = document.currentScript.sourceWindow;

… and then loop over all the frames (window.frames) looking for a match.

Since you are using window.top and not window.parent you might need to be recursive there.

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