0

How can I detect a link click inside a iFrame?

The Frame source changes a lot of times and I need to detect all link click inside the iFrame.

I try that already: Javascript - click link in iframe

JS:

$("#Source a").click();

HTML:

<iframe src="" name="Source" id="Source" scrolling="" frameborder="0" title="Anzeigebereich"></iframe>

3 Answers 3

1

you need to use .contents() http://api.jquery.com/contents/

$('#Source').on('load', function(){
    $(this).contents().find('body').on('click', 'a', function(e){
        e.preventDefault(e);//stop normal navigation
        //your code here
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

this work only on iframe hosted on the same web domain
0

If you trying to catch an event or do whatever inside the iframe from the oustide document, it isn't possible, the iframe is different context (different document) and this is not alowed. You can check a similar question here

Comments

0

use post message, for communicaton between frames, also support different domains

post message doc

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.