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

189
Vistas
Unable to fill src value using JS in iframe
<!DOCTYPE html>
<html>

<body style="text-align:center;">
    <iframe id="gfgFrame" src=""
        style="height: 50vh; width: 600px;">
    </iframe>

    <input type="text" id = "xxx">
  <p id = "u"></p>
    <button onclick="navigate()">
        Click it
    </button>

    <script>
    var url = document.getElementById("xxx");
        function navigate() {
            document.getElementById("gfgFrame").setAttribute("src", url);
      document.getElementById("u").innerHTML = "Hello";
    }
    </script>
</body>

</html>

If I enter a URL, it's not working. I have seen solutions on stackoverflow. I have also tried the other method, which is

    <script>
var url = document.getElementById("xxx");
       function navigate() {
            document.getElementById("gfgFrame").src
                = url;
        }
    </script>

Please forgive my intendation. Can anyone tell me where I'm going wrong?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You requesting element itself, not the value of this field, see:

const urlBlock = document.getElementById("xxx"); // get url text input

function navigate() {
  const iframe = document.getElementById("gfgFrame");
  const text = document.getElementById("u");
  
  // get url from input
  const url = urlBlock.value;
  
  iframe.setAttribute("src", url);
  text.innerHTML = "Hello";
}
<iframe id="gfgFrame" src="https://fr.wikipedia.org/wiki/Main_Page" style="height: 50vh; width: 600px;"></iframe>

<input type="text" id="xxx" value="https://wikipedia.org/wiki/Main_Page" />

<p id="u"></p>

<button onclick="navigate()">Click it</button>

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