Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top