The problem that occurs in your code is that the which
function is not supported in older versions of Internet Explorer, only from version 9 of it.
So to solve your problem, with a simple solution and cross browser capture of the enter key, you can do as follows below:
$(document).keypress(function(e){
var keycode = e.keyCode ? e.keyCode : e.which;
if(keycode === 13){
$('.button_ok').click();
}
});
$(document).keypress(function(e){
var keycode = e.keyCode ? e.keyCode : e.which;
if(keycode === 13){
$('.button_ok').click();
}
});
$('.button_ok').click(function() {
alert('OK!');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><inputtype="text" name="txt_input" />
<input type="button" class="button_ok" value="OK" />
$(window).keypress(function(e){
var keycode = e.keyCode ? e.keyCode : e.which;
if(keycode === 13){
$('.button_ok').click();
}
});
$('.button_ok').click(function() {
alert('OK!');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><inputtype="button" class="button_ok" value="OK" />