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

145
Vistas
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 Respuestas
Responde la pregunta

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 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