简体   繁体   中英

How to detect the “tab” keypress in Safari

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM