The problem with the prototype observation in Opera

I am using Prototype and doing Event.observe on window.document.

I will catch enter (keyCode 13) and alt + f (altKey && keyCode = 70).

My code works super with firefox, IE and chrome. With Opera no. The input is displayed, but only if my focus is not in any text input. Alt + F does not work at all.

Is this a bug in the prototype or do I need to do something "extra" for Opera to continue? As I said, in all other browsers my code works ....

+5
source share
2 answers

Firstly, this is a useful resource: http://unixpapa.com/js/key.html

-, , keydown ( keyup) . keypress , Opera . keydown .

keyCode === 13 Opera 11.10 , , , :

Event.observe(document, 'keydown', function (e) {
    alert(e.charCode+'::'+e.keyCode);
});

( attachEvent IE):

if (document.addEventListener) {
    document.addEventListener('keydown', function (e) {
        alert(e.charCode+'::'+e.keyCode);
    }, false);
}
else { // IE
    document.attachEvent('onkeypress', function (e) {
        alert(e.charCode+'::'+e.keyCode);
    });
}

, alt , ( Chrome IE). , Windows alt .

preventDefault() ( , ctrl-f, ), , , .

+2

Alt-F , Opera JavaScript .

0