Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
Manipular y agregar <script> a iframe

Digamos que tengo acceso a un index.html y dentro de esta página, estoy cargando un contact.html como iframe .

Puedo manipular este iframe y aquí está mi código:

 const myIframe = document.getElementById("myIframe"); const iframeDocument = myIframe.contentDocument; iframeDocument.body.style.backgroundColor = "#ff0000";

Puedo cambiar el color de fondo dentro de este iframe , pero lo que debo hacer es agregar código JavaScript al <body> de este documento iframe . Probé con innerHTML pero no funciona.

El código que necesito agregar se ve así:

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

Es importante agregar este código con etiquetas y ejecutarlo más adelante.

¿Tienes alguna idea de cómo hacerlo?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Primero, creé una página vacía llamada bar.html

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

luego creó una página foo.html también:

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

Por favor, pruebe esto como una prueba de concepto

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!