Detect Click into Iframe using JavaScript

前端 未结 21 2295
轻奢々
轻奢々 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:12

    You can achieve this by using the blur event on window element.

    Here is a jQuery plugin for tracking click on iframes (it will fire a custom callback function when an iframe is clicked) : https://github.com/finalclap/iframeTracker-jquery

    Use it like this :

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

提交回复
热议问题