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

105
Views
inserte window.location.href en iframe src en vainilla

Estoy tratando de descubrir cómo insertar la URL de la página actual en un iframe src que está cargado pero oculto en la misma página. No quiero usar jQuery por otras funciones.

Como puede ver, estoy tratando de copiar eso en un fragmento de iframe.

¡Cualquier ayuda será apreciada, gracias!

 <!DOCTYPE html> <html> <head> <title>Parcel Sandbox</title> <meta charset="UTF-8" /> <script rel="stylesheet" src="./src/styles.css"></script> </head> <body> <p id="p1" class="offscreen" aria-hidden="true"> <iframe id="card" src="http://window.location.href" width="20%" height="80%" frameborder="0" > </iframe> </p> <p id="p2">P2: I am a second paragraph</p> <button onclick="copyToClipboard('p1')">Copy P1</button> <button onclick="copyToClipboard('p2')">Copy P2</button> <br /><br /><input type="text" placeholder="Paste here for test" /> <!-- <script language="JavaScript"> var iframe = document.getElementById("card").src; iframe.write(window.location.href); </script> --> <script language="JavaScript"> function copyToClipboard(elementId) { var aux = document.createElement("input"); aux.setAttribute("value", document.getElementById(elementId).innerHTML); document.body.appendChild(aux); aux.select(); document.execCommand("copy"); document.body.removeChild(aux); } </script> </body> </html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simplemente asigne la URL en un <script> :

 if(window.top == window.self) { // otherwise you end up in infinite nested iframes const iframe = document.getElementById('card'); iframe.src = window.location.href; }
about 4 years ago · Juan Pablo Isaza 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!