Freitag, 8. Juli 2011

On event.preventDefault() error messages in IE 8 (9? 7? 6?)

If checking for event.preventDefault() you get error messages in IE.

A better way is to check for the existence of event.returnValue (which is IEs preventDefault()) and if it doesn't exist you know that you're not on IE.

if (event.returnValue) {
    // this is IE
    event.returnValue = false;
} else {
    // this is Chrome, Firefox, Safari etc.
    event.preventDefault();
}

Keine Kommentare:

Kommentar veröffentlichen