[removed] IE event.preventDefault is null or not an object

前端 未结 2 754
死守一世寂寞
死守一世寂寞 2020-12-21 16:17

My code works fine in FF/Chrome/Everything except IE(failed in both 7/8, didn\'t bother going furthur down). Due to restrictions, I cannot use jQuery and am hard-coding the

相关标签:
2条回答
  • 2020-12-21 16:32

    In IE the event object is not passed as the first argument to an event handler. Instead it is a global variable:

    function mousedown(e){
     var evt = e || window.event; // IE compatibility
     if(evt.preventDefault){  
      evt.preventDefault();  
     }else{  
      evt.returnValue = false;  
      evt.cancelBubble=true;  
     }
     //Processing   
    };
    
    0 讨论(0)
  • 2020-12-21 16:47

    IE has a different event model to other browsers (even IE8). In IE you would call this to do the same thing:

    event.returnValue = false;
    

    You need to determine what the browser supports and call the correct method. So first check if event.returnValue is set, if so then call it, otherwise call preventDefault().

    0 讨论(0)
提交回复
热议问题