Chrome not allowing tab prevendefault
Asked Answered
C

1

0

I have a form on which user can tab and jump to different elements. i was to stop the tab when it reaches a special anchor tag.

this is the code which work in firefox

    $('.next-tab').keypress(function(e){
        var code = (e.keyCode ? e.keyCode : e.which);
        console.log(code);
        if (code == 0 || code == 9){
            console.log("keypress")
            e.preventDefault();
            e.stopPropagation();
        }
    });

but this code does not work in chrome, i dont know why, it does not even enter the keypress method. so i used this code for chrome

$('.next-tab').blur(function(e) {
            var code = (e.keyCode ? e.keyCode : e.which);
            console.log(code);
            if (code == 0 || code == 9){
                console.log("blur")
                e.preventDefault();
                e.stopPropagation();
            }
        });

it enters the blur method pass the condition but dont do any thing, and user can easily move to the next element.

Cis answered 12/6, 2013 at 18:50 Comment(0)
V
2

For chrome support, looks like you need to use keydown event:

http://jsfiddle.net/qD2rk/

$('.next-tab').keydown(function (e) {
    var code = (e.keyCode ? e.keyCode : e.which);
    console.log(code);
    if (code == 0 || code == 9) {
        console.log("keydown")
        e.preventDefault();
        e.stopPropagation();
    }
});
Volvulus answered 12/6, 2013 at 19:1 Comment(1)
damn, why did i thought of that :(, Thanks a lot buddyCis

© 2022 - 2024 — McMap. All rights reserved.