Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$(window).keypress(function()) does not work in IE7?

This keypress event works fine for me in Chrome and Firefox, but simply isn't being picked up at all in IE7:

$(window).keypress(function(e) {
    alert('hello world');
});

Does anyone know alternatives for IE7?

Or is it an error higher up in my JavaScript that means it isn't being picked up in IE7 - in which case, how can I debug it? I have script errors turned on in IE, but nothing is popping up.

like image 239
AP257 Avatar asked Feb 17 '11 02:02

AP257


1 Answers

IE doesn't support key events on the window.

Place it on the document instead.

$(document).keypress(function(e) {
    alert('hello world');
});
like image 172
user113716 Avatar answered Oct 02 '22 07:10

user113716