IFrame Cross Domain Click Tracking

976 views Asked by At

The Below code was able to track the clicks on iframe but i was not able to know click (right/left/middle) ???

<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>

can some one help me on this issue...

1

There are 1 answers

0
buley On BEST ANSWER

You can't follow the clicks happening inside the iFrame, a policy put in place to prevent the exact kind of behavior you're trying to achieve.

What you're trying to do could be construed as "clickjacking."