Hi all,

I thought I just share that:

Say you are opening a dialog window with two buttons/links in it and
want to prevent that the focus goes right back to the page (which is
covered by an overlay and should be kind of disabled) while you are
using the tab key, not the mouse...:

1. Give both buttons a tabindex of 1000 and 1001 for example (a huge
number to ensure all elements on the page have a lower tabindex).

2. After the window has opened, if the tab key gets pressed focus the
first button (dialogWindow is a DOM element with all the stuff in it):

$(document).keypress(function(e) { // onekeypress bug?
     if (e.keyCode == 9) {
         // tab to first button
         $('button', dialogWindow).eq(0)[0].focus();
         $(document).unkeypress();
         return false;
     }
});

And then increase the tab index on every blur:

$('button', dialogWindow).blur(function() {
     this.tabIndex = ++this.tabIndex;
});

Voila, you won't be able to tab back into the page and instead tab
between the two buttons back and forth. Maybe that's useful for the
window plugin and/or thickbox...

By the way, onekeypress doesn't seem to work.


-- Klaus



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to