views:

68

answers:

2

I would like to detect the 'tab' keypress in Safari. It already works in IE and Firefox.

The trigger is on keypress. Both firefox and IE return key '9' which is Tab. But Safari looks like to ignore this. Both versions 4 and 5 seem to fail in detecting it. How do i detect it?

+1  A: 

To find out what gets detected have a look at W3Cs Key and Character Codes vs. Event Types page. There you can type and directly see what gets fired.

Thariama
A: 

Use the keyCode property of the keydown event. This will work in all mainstream browsers:

document.onkeydown = function(e) {
    e = e || window.event;
    if (e.keyCode == 9) {
        alert("Tab");
    }
};
Tim Down