有一个巧妙的方法来对iframe中的内容得到了“点击”。
你可以这样做:
<div id="iframeinside">
<iframe />
</div>
现在,这使得它能够在JS类似地说:
var oldActive = document.activeElement; /* getting active Element */
var frame = $('#iframeinside iframe')[0];
$('#iframeinside').mouseenter(function() {
/* Setting interval to 1ms for getting eventually x,y mouse coords*/
oldActive = document.activeElement;
setInterval('doSomething()', 1);
});
$('#iframeinside').mouseleave(function() {
/* clear interval cause we arent over the element anymore*/
clearInterval(intervalId);
});
这些间隔做电:
function doSomething() {
/* if the focus has changed to the iframe */
if(oldActive != frame && document.activeElement == frame) {
oldActive = document.activeElement;
alert(myQuery);
alert('click did happen to the iframe');
}
}
我用这对几件事情,它总是奏效。我没有检查是怎么样ie6,7和哥哥。
由于安全限制,这不起作用。 – Oliver 2013-02-23 02:11:01
谢谢。任何其他方式捕捉点击,也许在iframe的区域根据鼠标x,y ..任何建议 – 2013-02-23 02:12:38
你可以覆盖一个透明的div,但然后用户将不得不点击两次。对不起,没有方便的解决方案。 – Oliver 2013-02-23 02:14:33