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

169
Vistas
Stop iframe from redirect to new window and replace its source

I hope I'll find a solution to my problem here. Suppose it is a code:

<iframe src="https://anyweb.ext/anymouse"></iframe>

As the page loads, it gets redirected to a new window. I want it not to be redirected, but the redirected URL should be replaced with iframe src="". I want to do it JavaScript.

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

0

Method-1

If you assign data-src to the src attribute of the <iframe> element using Javascript, the <iframe> will open on the same page.

const mainPageButton = document.getElementById('mainPageButton');
const talkPageButton = document.getElementById('talkPageButton');
const iframeElement = document.getElementById('specialIFrame');
const mainPage = "https://en.wikipedia.org/";

/* Opens the "data-src" attribute of the <iframe> element. */
mainPageButton.addEventListener('click', function(){
  iframeElement.setAttribute("src", mainPage)
});

/* Opens the address defined in the mainPage variable. */
talkPageButton.addEventListener('click', function(){
  iframeElement.setAttribute("src", iframeElement.dataset.src)
});
button { margin-bottom: 10px; margin-left: 75px; }
<button id="mainPageButton">OPEN Main Page</button>
<button id="talkPageButton">Open Talk Page</button><br>

<iframe id="specialIFrame" data-src="https://en.wikipedia.org/wiki/Talk:Main_Page" src="about:blank" width="500"></iframe>

Method-2

Adding the target attribute to the <a> element and the name attribute to the <iframe> element opens the website within the same page.

a{ display: block; }
<a target="myIframe" href="https://en.wikipedia.org/wiki/Main_Page">Open</a> 

<iframe name="myIframe"></iframe>

References
  • Open link in <iframe>
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