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

216
Vistas
Manipulating and adding <script> to iframe

Let's say I have access to an index.html and within this page, I'm loading a contact.html as iframe.

I can manipulate this iframe and here's my code:

const myIframe = document.getElementById("myIframe");  

const iframeDocument = myIframe.contentDocument;
     
iframeDocument.body.style.backgroundColor = "#ff0000";

I can change background color within this iframe, but what I need to do is to append JavaScript code to the <body> of this iframe document. I tried with innerHTML but it's not working.

The code that I need to append looks like this:

<script>
  iframe(function (event) {
    const frameTest = true;
    if (!iframe) {
      test(event);
    } else {
      testo(event);
    }
  </script>

It's important to add this code with tags and execute it later on.

Do you have any idea how to do it?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

First, I created an empty page called bar.html

<html>
        <head>
        </head>
        <body>
        </body>
</html>

then created a foo.html page as well:

<html>
        <head>
                <script>
                function load() {
                    const myIframe = document.getElementById("myIframe");
                    const iframeDocument = myIframe.contentWindow;
                    var script = document.createElement("script");
                    script.innerText = "alert(1)";
                    iframeDocument.document.body.appendChild(script);
                }
                </script>
        </head>
        <body onload="load()">
                <iframe id="myIframe" src="/bar.html">
        </body>
</html>

Please test this as a proof-of-concept

about 4 years ago · Santiago Gelvez 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