如何使用javascript捕获点击iframe

时间:2014-06-10 13:59:04

标签: javascript html iframe

如何使用javascript捕获点击iframe。

我正在使用此代码:

document.getElementsByClassName('pin').contentWindow.document.body.onclick = 
function() {
  alert("iframe clicked");
}

但它无法捕获iframe的任何点击。我只能使用javascript。 我收到了这个错误 " SecurityError:使用origin"

阻止了一个帧

1 个答案:

答案 0 :(得分:0)

var i = 0; 
//i represents the exact node since obtaining node by class name gives array of nodes.
var iframe = document.getElementsByClassName('pin')[i].contentWindow;

var iframe = document.getElementById("iframe_id").contentWindow;

iframe.document.body.onmousedown = 
function() {
  alert("iframe clicked");
}