IFrame跨域点击跟踪

IFrame Cross Domain Click Tracking

本文关键字:跟踪 IFrame      更新时间:2023-09-26

下面的代码能够跟踪iframe上的点击,但我不知道点击(右/左/中)???

<script> 
var isOverIFrame = false;
function processMouseOut() {
    isOverIFrame = false;
    top.focus();
}
function processMouseOver() {
    isOverIFrame = true;
}
function processIFrameClick() {
    if (isOverIFrame) {
        //was clicked
        console.log('tracking');
    }
}
function init() {
    var element = document.getElementsByTagName("iframe");
    for (var i = 0; i < element.length; i++) {
        element[i].onmouseover = processMouseOver;
        element[i].onmouseout = processMouseOut;
    }
    if (typeof window.attachEvent != 'undefined') {
        top.attachEvent('onblur', processIFrameClick);
    }
    else if (typeof window.addEventListener != 'undefined') {
        top.addEventListener('blur', processIFrameClick, false);
    }
} 
</script>
<iframe src="http://google.com"></iframe> 
<script>init();</script>

有人能在这个问题上帮我吗。。。

您不能跟踪iFrame内部发生的点击,这是一项旨在防止您试图实现的行为的策略。

你试图做的事情可以被理解为"点击劫持"。