IE8下获取iframe document EVENT对象的问题

在一个页面中设置iframe的document Onclick 事件获取在iframe中的document被点击的对象,W3C如下:

document.getElementById('iframe的ID').contentDocument.onclikc=function(event){}

以上的EVENT对象在W3C浏览器下可以得到,在IE8中就无法得到,原因有2个,一是IE下的iframe的document对象和W3C不同,二是EVENT对象是根据当前窗口来决定的,如IE下的EVENT对象,是window.event,iframe中就是iframe窗口的event对象而W3C是event到底而不像W3C智能。解决方法如下:

document.getElementById('iframe的ID').contentWindow.document.onclick=function(event){

  var event= document.getElementById('iframe的ID').contentWindow.event;

}

这样就能得到iframe窗口中的document文档点击的对象了。

原文地址:https://www.cnblogs.com/strangerqt/p/3627852.html