PreventDefault alternative for IE8

前端 未结 4 1797
误落风尘
误落风尘 2020-12-04 01:17

Situation: Trying to modify VideoJS.com in order to work with IE8 and Youtube Chromeless API.

Problem: Progressbar dragging doesn\'

相关标签:
4条回答
  • 2020-12-04 01:57

    I use something like:

    (event.preventDefault) ? event.preventDefault() : event.returnValue = false; 
    

    the event.returnValue property is the closest IE equivalent to preventDefault.

    Using

    return false;
    

    can sometimes also work, but it can lead to unexpected behavior sometimes when mixed with e.g. jQuery (jQuery also does stopPropagation...which is usually what you want, but...), so I prefer not to rely on it.

    0 讨论(0)
  • 2020-12-04 02:20

    IE8 does not support preventDefault; it has returnValue instead. jQuery should normalize that for you, though. Are you sure you are calling preventDefault on the jQuery event wrapper (and not the actual event object)?

    0 讨论(0)
  • 2020-12-04 02:20

    Use

    $('.selector').click(function(event) {event.preventDefault();
    

    jquery docs

    0 讨论(0)
  • 2020-12-04 02:22

    Just use

    return false;
    

    it's cross browser and has the same purpose as event.preventDefault();

    THe same instruction in jQuery is slightly different, it includes also stopPropagation().

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