如何使用javascript捕获点击iframe。
我正在使用此代码:
document.getElementsByClassName('pin').contentWindow.document.body.onclick =
function() {
alert("iframe clicked");
}
但它无法捕获iframe的任何点击。我只能使用javascript。 我收到了这个错误 " SecurityError:使用origin"
阻止了一个帧答案 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");
}