0

Quiero que al dar click en la etiqueta a el link pase al iframe y se cargue

<a href="https://www.google.com">Cargar</a>

<iframe id="container" src=""></iframe>

2 respuestas 2

2

Tambien puedes resolverlo sin javascript

<iframe src="pagina.html" name="iframe_a"></iframe>
<a href="https://www.w3schools.com" target="iframe_a">W3Schools.com</a>

Solo tienes que ponerle un "name" al iframe y poner el nombre del name dentro del target del link.

Puedes revisar mas sobre esto en:
https://www.w3schools.com/html/html_iframe.asp
https://www.w3schools.com/html/tryit.asp?filename=tryhtml_iframe_target

2

espero que esto te sirva.

Se me ocurren muchas maneras de hacerlo, pero te dejo una sencilla, que es utilizando JavaScript.

Solo te recomiendo que leas sobre X-Frame-Options, porque hay algunas limitaciones con iframe.

Puedes leer más aquí https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options

<a href="#" onclick="changeURL()" >Cargar</a>

  <iframe id="container" src=""></iframe>

  <script>
      function changeURL() {
            var ifr = document.getElementById("container");
            ifr.setAttribute("src", "https://www.iqstudiogt.com");          
      }
  </script>

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.