开发者

How to detect the "tab" keypress in Safari

开发者 https://www.devze.com 2023-01-03 10:31 出处:网络
开发者_JAVA技巧I would like to detect the \'tab\' keypress in Safari. It already works in IE and Firefox.

开发者_JAVA技巧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?


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.


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");
    }
};
0

精彩评论

暂无评论...
验证码 换一张
取 消