Search code examples
javascriptfirefoxdom-eventsextjs4

ExtJs event propagation "unstoppable" on Firefox


I am trying to prevent navigation back when hitting a backspace in an ExtJs application. So far I have the following code:

Ext.EventManager.on(window, 'keydown', function (e, t) {
    if (e.getKey() == e.BACKSPACE && (!/^(input|text|password|file|textarea)$/i.test(t.tagName.toLowerCase()) || t.disabled || t.readOnly || /^button$/i.test(t.type.toLowerCase()))) {
        if (!confirm("Are you sure you want to navigate back ?")) {
            if (e.preventDefault) {
                e.preventDefault();
                e.stopPropagation();
            } else {
                e.returnValue = false;
            }
        }    
    }
});

The thing is that on Chrome and IE it works fine, but on Firefox the navigation is not prevented. I have tried:

e.stopImmediateProgpagation()
e.stopEvent()
e.cancelBubble = true;
return false;

but none of them seems to work. Can you help me figure this out? PS: I am using ExtJs4.0.7


Solution

  • It looks like it is necessary to add the listener to "keypress" event to make it work.