Detect Click into Iframe using JavaScript

前端 未结 21 2292
轻奢々
轻奢々 2020-11-22 03:06

I understand that it is not possible to tell what the user is doing inside an iframe if it is cross domain. What I would like to do is track if the user clicke

21条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 03:36

    Combining above answer with ability to click again and again without clicking outside iframe.

        var eventListener = window.addEventListener('blur', function() {
        if (document.activeElement === document.getElementById('contentIFrame')) {
            toFunction(); //function you want to call on click
            setTimeout(function(){ window.focus(); }, 0);
        }
        window.removeEventListener('blur', eventListener );
        });
    

提交回复
热议问题