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

360
Vistas
Disable all links inside IFRAME using jQuery

I want to disable all links inside an IFRAME, when people click on those link, alert would popup.

Here is what I have so far, but the jQuery does nothing. Not sure what I did wrong.

<iframe id='templateframe' name='templateframe' src="templates/template<?php echo $templateID; ?>/login.html"></iframe>

$(document).ready(function(){       
        $('#templateframe').contents().find('a').click(function(event) {
            alert("demo only");

            event.preventDefault();

        }); 
});

Thanks in advance.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

I would expect that $(document).ready executes before the content of the iframe has loaded. Try using the onload attribute for the iframe instead.

over 4 years ago · Santiago Trujillo Denunciar

0

I was looking to disable iframe links too and couldn't find a solution. Thanks to HTML5, you can easily disable links by simply adding the sandbox attribute.

<iframe src="externalsite.com" sandbox></iframe>

view demo

I hope this helps someone searching the net, especially since this questions pops up first on Google.

over 4 years ago · Santiago Trujillo Denunciar

0

The solution mentioned by "lol" actually works quite well. I stumbled on this accidentally after working on this for a couple of hours...

Put your iframe inside a div element, then make the div transparent and push the z-index of the iframe behind the div. See this example:

<div class="container">
  <iframe class="lockframe" src="www.google.com"></iframe>
</div>

Then set up your css like this:

div.container { background: transparent; }
iframe.lockframe { z-index: -2; }

Load up your page and the div is what will accept the click events, not the iframe.

over 4 years ago · Santiago Trujillo 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