Reputation: 65
I have a working code:
document.onkeypress=function(e){
if( e.keyCode==49 ){
e.preventDefault();
alert('Переход на целевую страницу при нажатии 1');
window.location.href="http://yandex.ru";
}
};
But it doesn't work if I try to assign key like F1, F2, F3 Chrome opens Help (F1) and so on. e.preventDefault();
doesn't work.
How can I update my code?
Upvotes: 0
Views: 49
Reputation: 393
In some browsers keypress doesn't work but keydown works. You may want to reference this: http://www.quirksmode.org/js/keys.html.
I hope this helps.
Upvotes: 1