I'm trying to achieve exactly what you've done in this thread: Remove anchor links / form targets within iframe content
I've tried wrapping the jQuery in a function like this:
$('#ifr').load(function(){
$('#ifr').contents().find('a').click(function() { return false; });
}
But that isn't working. Do you have any tips or suggestions?
You have to bind the event when the iframe
has loaded. And use e.preventDefault()
to stop the default behavior.
Example on jsFiddle
$("iframe").load(function() {
// note the use o .each, you need to bind all elements
$(this).contents().find("a").each(function() {
$(this).click(function(e){e.preventDefault(); alert("click blocked")});
});
});
The iframe
must be from the same origin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With