Click-event on iframe?

后端 未结 2 1181
走了就别回头了
走了就别回头了 2021-01-13 17:36

I have a simple iFrame … 


         


        
2条回答
  •  -上瘾入骨i
    2021-01-13 18:19

    You cannot do this because of web browser's same origin policy.

    But you can use a workaround with the blur event and mouseover/mouseout events. That's how works my iframeTracker jQuery plugin, designed to track clicks on iframes : https://github.com/finalclap/iframeTracker-jquery

    Here is an example :

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

    Enjoy !

提交回复
热议问题