PreventDefault alternative for IE8

MeProtozoan picture MeProtozoan · Dec 12, 2010 · Viewed 19.2k times · Source

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?

Answer

Kevin Horn picture Kevin Horn · Dec 9, 2011

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.