11

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

Problem: Progressbar dragging doesn't work (error on event.preventDefault(); 'not supported' according to debug)

Demo: http://alpha.dealertouch.mobi/video/demo.html

What I tried: Skip 'preventDefault' when it's IE, but if I do that I'll lose the functionality of the progressbar (drag/click forward and backward)

Question: What is the best way to solve this problem for IE8?

bfavaretto
  • 71,580
  • 16
  • 111
  • 150
MeProtozoan
  • 1,027
  • 3
  • 14
  • 26

4 Answers4

29

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.

Kevin Horn
  • 4,167
  • 28
  • 30
5

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)?

Tgr
  • 27,442
  • 12
  • 81
  • 118
1

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().

sebarmeli
  • 17,949
  • 7
  • 35
  • 40
  • See http://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false for a caveat of this approach. – Bungle Jan 20 '14 at 21:46
-1

Use

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

jquery docs

Traveling_Monk
  • 778
  • 2
  • 11
  • 28