0

https://jsfiddle.net/r1x8gyha/1/

<script type="text/javascript">
$(window).load(function(){
$(function() {
    $("body").click(function(e) {
        if (e.target.id == "xxx") { 
            alert("Inside div");
        }
    });
})
});
</script>

<div id="xxx" style="background: red;">
<iframe width="420" height="315"
src="https://www.youtube.com/embed/JGwWNGJdvx8">
</iframe>
</div>

When click inside iframe for play video. why jacascript not alert ?

(iframe is inside elements id xxx)

6
  • The frame content is on a remote domain, so you cannot receive events from it. What you're trying to do isn't possible. Commented Mar 9, 2017 at 8:27
  • please advice me. how can i do ? Commented Mar 9, 2017 at 8:28
  • That's the point, you can't. In terms of browser security, this is a very, very good thing. Commented Mar 9, 2017 at 8:29
  • It's possible with postMessage, e.g. stackoverflow.com/questions/17816373/… Commented Mar 9, 2017 at 8:30
  • change " $("body").click(function(e) { " to $("iframe").click(function(e) { Commented Sep 13, 2019 at 6:06

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.