我试图防止在 ExtJs 应用程序中点击退格键时导航回来。到目前为止,我有以下代码:
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;
}
}
}
});
问题是在Chrome和IE上它工作正常,但在Firefox上不会阻止导航。我试过:
e.stopImmediateProgpagation()
e.stopEvent()
e.cancelBubble = true;
return false;
但它们似乎都不起作用。 你能帮我弄清楚吗?PS:我正在使用ExtJs4.0.7
看起来有必要将侦听器添加到"按键"事件中才能使其工作。