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.
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)?
in IE, you can use
event.returnValue = false;
to achieve the same result.
And in order not to get an error, you can test for the existence of preventDefault:
if(event.preventDefault) event.preventDefault();
source -
http://stackoverflow.com/questions/4422045/preventdefault-alternative-for-ie8
http://stackoverflow.com/questions/1000597/event-preventdefault-function-not-working-in-ie
'Development > JavaScript' 카테고리의 다른 글
javascript - Naming Conventions (0) | 2014.07.18 |
---|---|
javascript - 이벤트 리스트(event list) (0) | 2014.05.16 |
javascript - requestAnimationFrame (0) | 2014.04.02 |
javascript - 초에서 시간, 분 구하기 (0) | 2014.04.01 |
javascript - Find angle between hour and minute hands in an analog clock (0) | 2014.04.01 |