1

Got a js that appends an iframe with content from other site. I need certain action to be triggered on click within the iframe.

Obviously, i can't use elements inside iframe. I've tried following, and it didn't work.

$('.container iframe').click(function(){
   alert('works!");
});

Then I tried this.

$('.container').click(function(){
   alert('works!");
});

click on container works, but when click happens within iframe, it doesn't work.

Can someone point me in right direction? Thank you!

Arazam
  • 71
  • 1
  • 7
  • 1
    I'm afraid this is not possible. If you were able to listen for events on the content of the iframe, it would be open to abuse. – Stefan Pante Mar 25 '15 at 20:15

1 Answers1

0
    var iframeBody = $('body', $('.container iframe')[0].contentWindow.document);
    $(iframeBody).on('click', function(e) {
        // your code
    });
Banik
  • 911
  • 6
  • 10