0

I have a page on my site that uses an iframe, what i am doing is, if the user clicks any where in the iframe, they get a popup message:

alert('To learn more about this product please click on the \'Read More\' button.');

The code i put together is:

<div class="embed-responsive embed-responsive-16by9"><iframe class="embed-responsive-item" id="iframe" src="http://zzzzz.<?php echo $id; ?>.site2.net/" allowfullscreen></iframe></div>

<!-- Iframe -->
<script>
var monitor = setInterval(function(){
    var elem = document.activeElement;
    if(elem && elem.tagName == 'IFRAME'){
        alert('To learn more about this product please click on the \'Read More\' button.');
        clearInterval(monitor);
    }
}, 100);
</script>

Currently the code does popup the message as expected, but only pops up once, if i try to re-click inside the iframe, there is no popups, am i missing something obvious? any help is appreciated.

colinreedy674
  • 365
  • 2
  • 12
  • First observation is you aren't detecting if the user clicks in the iframe, you are detecting in 100 milliseconds if it has focus *activeelement. Once it has focus, the user would have to click out of it and click in it again to trigger your code. – imvain2 Feb 21 '19 at 19:18
  • Possible duplicate of [Detect Click into Iframe using JavaScript](https://stackoverflow.com/questions/2381336/detect-click-into-iframe-using-javascript) – imvain2 Feb 21 '19 at 19:19

0 Answers0