Detect click on an iframe

0

I have an iframe:

<div class="recebe_iframe">
    <iframe class="caixa_iframe" src="https://www.youtube.com/embed/dfsdfsdf"frameborder="0" allowfullscreen></iframe>
</div>

I wanted to use jquery to detect when a user clicks on this youtube iframe, or even in this recebe_iframe div. It can be when the user clicks on it, anywhere, it can be play, pause, volume, it does not matter ... just detect that click.

    
asked by anonymous 06.02.2018 / 16:02

2 answers

0

You can use:

$( "recebe_iframe" ).click(function() {
  //código
});

As it is not very clear what you are looking for, this can get you some north.

Example:

$( "p" ).click(function() {
  $( this ).slideUp();
});
p {
    color: red;
    margin: 5px;
    cursor: pointer;
  }
  p:hover {
    background: yellow;
  }
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>click demo</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script></head><body><p>FirstParagraph</p><p>SecondParagraph</p><p>YetonemoreParagraph</p></body></html>

Reference: jQuery API Documentation

    
06.02.2018 / 16:10
0

The click does not take to capture, what to do is to check when there was a hover in the div that the frame is involved.

$(document).ready( function() {
    var frame = -1;
    $('iframe').hover( function() {
        alert('hover')
    }, function() {
        frame = -1
    });
        $(window).blur( function() {
        if( frame != -1 ) 
            alert('desapareceu'); 
    });
});
  
    
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
></script>
<div class='banner'>
    <iframe src='http://somedomain.com/whatever.html'></iframe>
<div>
    
06.02.2018 / 16:27