preventDefault() not stopping default browser behavior for Ctrl-PgUp and Ctrl-PgDn
I'm trying to implement WAI-ARIA keyboard controls for an accordion, and I'm stuck on getting Ctrl-PgUp and Ctrl-PgDn to work correctly. I've written the code to handle the correct behavior for the accordion, but I can't stop certain browsers from continuing their default behavior of switching between browser tabs.
Both Firefox 3.6.4 and Chrome 5 insist of switching the browser tab, although Firefox still performs the scripted accordion behavior. Chrome does not. Safari 5 and IE 7 both behave correctly, and perform the accordion actions without switching browser tabs.
My code looks like this:
$(document).keydown(function(e) {
var el = document.activeElement;
switch (e.which) {
//other key commands go here
case 34:
//Ctrl+PgDn
if(e.ctrlKey && $(el).parents('#accordion').length > 0) {
e.preventDefault();
e.stopImmediatePropagation();
e.cancelBubble = true;
e.returnValue = false;
// do the accordion stuff
}
break;
}
}
It should check if the user has pressed Ctrl-PgDn and is focused within the accordion, and then cancel the browser's default behavior, but none of it works. I started with just preventDefault(), but added the others as I became more and more frustrated. Is there any solution to this?