Disable Return key using jQuery – IE Bug

Once again IE stops a developer in his tracks and forces him to rewrite something that works perfectly in every other browser. This time – disabling Return using jQuery.

This works for everyone except Microsofts (quirky) browser. More enamel is lost in a year through developers teeth grinding that I’m sure dental profits are soaring through the roof. Anyway:

$(window).keyup(function(e) 
{    
    if (e.keyCode == 13)
    { 
       e.preventDefault();         
        return false;
    }
});

Whereas this will work

$('#my-form').bind("keypress", function (e) {
    if (e.keyCode == 13) 
    {
        e.preventDefault();
        return false;
    }
});

Irritating. Boycott IE!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s