在非IE浏览器下兼容IE的event

JavaScript代码
  1. if(!document.all){   
  2.     HTMLElement.prototype.__defineGetter__("runtimeStyle"function(){   
  3.         return this.style;   
  4.     });    
  5.     window.constructor.prototype.__defineGetter__("event"function(){   
  6.         return __window_event_constructor();    
  7.     });   
  8.     Event.prototype.__defineGetter__("srcElement"function(){   
  9.         return this.target;   
  10.     });   
  11.     function __window_event_constructor(){    
  12.         if(document.all){    
  13.             return window.event;    
  14.         }    
  15.         var _caller = __window_event_constructor.caller;    
  16.         while(_caller!=null){    
  17.             var _argument = _caller.arguments[0];    
  18.             if(_argument){    
  19.                 var _temp = _argument.constructor;    
  20.                 if(_temp.toString().indexOf("Event")!=-1){    
  21.                     return _argument;    
  22.                 }    
  23.             }    
  24.             _caller = _caller.caller;    
  25.         }    
  26.         return null;    
  27.     }   
  28. }  

 

只要在页面运行时加上以上代码,非IE浏览器也可以使用IE特有的event事件了。 :)

引用通告地址: 点击获取引用地址
标签: event javascript 兼容
评论: 0 | 引用: 0 | 阅读: 1284 | 打印 | 打包