Detect click inside iframe

I want to detect, press INSIDE iframe is not onclick on the iframe itself, I tried the onclick event. u must click on the iframe itself to call the function. I even tried addeventlistener for a window or document nothing worked, as if the iframe function never triggers when I click inside the iframe :( plz help

+5
source share
5 answers

Only works with iframes in one domain:

$('body', $('select-your-iframe-here').contents()).click(function(event) {
  console.log('Clicked! ' + event.pageX + ' - ' + event.pageY);
});
+9
source

Web browsers will not allow you to access iframe content for security reasons (unless the iframe is in the same domain as the parent page).

, , iframe ( , iframe , ).

jQuery, iframe, : https://github.com/finalclap/iframeTracker-jquery. http://www.finalclap.com/tuto/track-iframe-click-jquery-87/ ( -).

, iframe, , :

jQuery(document).ready(function($){
    $('.iframe_wrap iframe').iframeTracker({
        blurCallback: function(){
            // Do something when iframe is clicked (like firing an XHR request)
        }
    });
});
+6

$(window).click( function(e){
    $('#result').text('Clicked inside document');
});

$(window).blur( function(e){
    $('#result').text('Clicked out of the window or on the iframe');
});​

test http://jsfiddle.net/4vBRe/

iframe, mouseover,

+3

IFRAME, -. IFRAME , , , , IFRAME.

, - - IFRAME: ed, . . Mousehole by _why .

+2

DIV IFRAME.
DIV , IFRAME.
CSS- z-index.

Then, when you click on IFRAME, the DIV receives the event.

But since the world is not perfect, now you have lost the ability to click inside the IFRAME.

0
source

All Articles